
:root {
    --primary: #007bff;
    --primary-dark: #0056b3;
    --success: #28a745;
    --danger: #dc3545;
    --bg: #eef1f6;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --radius: 16px;
    --header-h: 64px;
    --tabbar-h: 72px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-max-w: 430px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
}

/* ── App Shell ── */

.app-body {
    display: flex;
    justify-content: center;
    min-height: 100dvh;
    background: linear-gradient(180deg, #dbeafe 0%, var(--bg) 120px);
}

.app {
    width: 100%;
    max-width: var(--app-max-w);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
    box-shadow: var(--shadow);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

.app-header-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header-logo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.app-header-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-header-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.app-header-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
}

/* ── Bottom Tab Bar ── */

.app-tabbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--app-max-w);
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 200;
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}

.app-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    transition: color 0.2s;
    padding: 8px 4px;
    position: relative;
}

.app-tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 3px 3px;
}

.app-tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.app-tab-icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    transition: transform 0.2s;
}

.app-tab.active {
    color: var(--primary);
}

.app-tab.active .app-tab-icon svg {
    transform: scale(1.08);
}

.app-tab:active .app-tab-icon svg {
    transform: scale(0.92);
}

/* ── Toast ── */

.app-toast {
    position: fixed;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(26, 26, 26, 0.88);
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    white-space: nowrap;
    max-width: calc(var(--app-max-w) - 32px);
}

.app-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Cards ── */

.app-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
    border: 1px solid var(--border);
}

.app-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 14px;
}

.app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.app-card-header .app-card-title {
    margin-bottom: 0;
}

/* ── Form ── */

.container, .invoice-container {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

h1 {
    display: none;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group input,
.form-group textarea,
.item-row input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    background: #f9fafb;
    transition: border-color 0.2s, background 0.2s;
    appearance: none;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.item-row input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.form-group input[readonly] {
    background: #f3f4f6;
    color: var(--text-muted);
}

.items-section {
    margin: 0;
}

.items-section h3 {
    display: none;
}

.item-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    padding: 14px;
    background: #f9fafb;
    border-radius: 12px;
    border: 1.5px solid var(--border);
}

.item-row:last-child {
    margin-bottom: 0;
}

.quantity-unit {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.unit-select {
    padding: 14px 12px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: white;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    min-width: 72px;
}

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 14px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
}

button:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: #eef4ff;
    color: var(--primary);
}

.btn-secondary:active {
    background: #dbeafe;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 10px;
}

.submit-btn, .app-submit {
    width: 100%;
    padding: 16px;
    font-size: 17px;
    background: linear-gradient(135deg, #22c55e, var(--success));
    border-radius: 14px;
    margin-top: 4px;
    box-shadow: 0 4px 14px rgba(40, 167, 69, 0.35);
}

.submit-btn:active, .app-submit:active {
    background: linear-gradient(135deg, #16a34a, #218838);
}

.remove-item {
    background: #fef2f2;
    color: var(--danger);
    padding: 12px;
    font-size: 14px;
}

.remove-item:active {
    background: #fee2e2;
}

#add-item {
    width: auto;
}

/* ── Invoice ── */

.invoice-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 16px;
}

.company-logo {
    max-width: 100%;
    width: 100%;
    max-width: 280px;
    height: auto;
    object-fit: contain;
}

.invoice-details {
    margin-bottom: 16px;
    color: #444;
}

.invoice-details p {
    margin: 6px 0;
    font-size: 15px;
}

.invoice-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
    min-width: 480px;
}

.invoice-table th,
.invoice-table td {
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 8px;
    text-align: left;
    font-size: 13px;
}

.invoice-table th {
    background-color: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 12px;
}

.invoice-table tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.invoice-table tfoot tr {
    background-color: #e9ecef;
}

.invoice-table tfoot td {
    border-bottom: none;
}

.total-label {
    text-align: right;
    font-size: 14px;
}

.total-amount {
    color: var(--success);
    font-size: 15px;
    font-weight: 700;
}

/* ── Action Bar ── */

.app-action-bar,
.actions,
.button-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 14px;
    padding: 0;
}

.action-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px !important;
    font-size: 14px !important;
    border-radius: 12px !important;
    flex: 1;
    min-width: 0;
    justify-content: center;
}

.action-chip svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

.print-btn { background: var(--primary); }
.pdf-btn { background: #e74c3c; }
.whatsapp-btn { background: #25d366; }

.back-btn {
    background: #6c757d;
    color: white;
    text-decoration: none;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    font-weight: 600;
}

/* ── Footer / Contact ── */

.footer-info {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: #555;
}

.footer-info p {
    margin: 8px 0;
    font-size: 15px;
}

.contact-card .contact-item,
.contact-card .contact-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.contact-card .contact-item:last-child,
.contact-card .contact-link:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.contact-card .contact-item:first-of-type,
.contact-card .contact-link:first-of-type {
    padding-top: 0;
}

.contact-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.contact-link {
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 16px;
}

.contact-item.copyable-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.contact-item .copyable-value {
    width: 100%;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.qr-card {
    text-align: center;
}

.copyable-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.copyable-value {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: #f8f9fb;
    color: #5c6773;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.copy-btn:active {
    background: #eef4ff;
    border-color: var(--primary);
    color: var(--primary);
    transform: none;
}

.copy-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.copy-btn .check-icon { display: none; }

.copy-btn.copied {
    background: #e8f7ee;
    border-color: var(--success);
    color: var(--success);
}

.copy-btn.copied .copy-icon { display: none; }
.copy-btn.copied .check-icon { display: block; }

.qr-code {
    margin-top: 8px;
}

.qr-code img {
    max-width: 140px;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 12px;
}

/* ── Print ── */

@page { margin: 0; }

@media print {
    body, .app-body {
        background: white;
    }

    .app-header,
    .app-tabbar,
    .app-action-bar,
    .actions,
    .button-group,
    .copy-btn,
    .app-toast {
        display: none !important;
    }

    .app {
        max-width: 100%;
        box-shadow: none;
    }

    .app-content {
        padding: 20px;
        overflow: visible;
    }

    .invoice-container {
        box-shadow: none;
        border: none;
        padding: 0;
    }
}

/* ── Desktop: phone frame ── */

@media (min-width: 480px) {
    .app-body {
        padding: 24px 0;
        align-items: flex-start;
    }

    .app {
        min-height: calc(100dvh - 48px);
        border-radius: 24px;
        overflow: hidden;
    }

    .app-tabbar {
        border-radius: 0 0 24px 24px;
    }
}

@media (max-width: 360px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .action-chip {
        flex: 1 1 100%;
    }
}

