@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    transition: background var(--transition), color var(--transition);
}

/* ─── LAYOUT ─────────────────────────────────────────── */
.app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

/* ─── SIDEBAR (desktop) ─────────────────────────────── */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--nav-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 0.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}
.sidebar-brand svg { color: var(--primary); }
.sidebar-brand h1 { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.sidebar-brand span { font-size: 0.65rem; color: var(--text-muted); display: block; font-weight: 400; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--nav-text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: all var(--transition);
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--nav-active); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; }

/* ─── MAIN AREA ─────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.topbar {
    height: 60px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
.topbar h2 { font-size: 1.1rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

.content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

/* ─── BOTTOM NAV (mobile) ───────────────────────────── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--nav-bg);
    border-top: 1px solid var(--border);
    padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 100;
    box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.bnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--nav-text);
    font-size: 0.625rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.bnav-item.active { color: var(--nav-active); }
.bnav-item svg { width: 22px; height: 22px; }

/* ─── SETUP / CONNECT SCREENS ───────────────────────── */
.screen {
    display: none;
    flex: 1;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.screen.active { display: flex; }

.setup-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 440px;
    animation: fadeUp 0.4s ease;
}
.setup-card .logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}
.setup-card .logo-area svg { color: var(--primary); }
.setup-card .logo-area h1 { font-size: 1.4rem; font-weight: 800; }
.setup-card p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem; line-height: 1.6; }

.connect-card {
    text-align: center;
    padding: 3rem 2rem;
}
.connect-icon {
    width: 72px; height: 72px;
    background: var(--primary-light);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    color: var(--primary);
}
.connect-card h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }

/* ─── LOADING OVERLAY ───────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 1rem;
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
}
.loading-overlay.hidden { display: none; }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ─── CARDS / SECTIONS ──────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-title { font-size: 1rem; font-weight: 700; }

/* ─── STATS GRID ────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1.1; margin-top: 0.25rem; }

/* ─── DATA TABLE ────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    padding: 0.625rem 0.875rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 0.75rem 0.875rem; vertical-align: middle; }

/* ─── QUOTE CARDS ───────────────────────────────────── */
.quote-list { display: flex; flex-direction: column; gap: 0.75rem; }
.quote-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow var(--transition), transform var(--transition);
}
.quote-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.quote-num {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    white-space: nowrap;
}
.quote-info { flex: 1; min-width: 0; }
.quote-client { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.quote-total { font-weight: 800; font-size: 1rem; color: var(--primary); white-space: nowrap; }
.quote-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* ─── BUTTONS ───────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(79,70,229,.3); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: 0 4px 14px rgba(79,70,229,.4); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #DC2626; transform: translateY(-1px); }
.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.danger:hover { background: #FEE2E2; color: var(--danger); border-color: #FECACA; }
.btn-success { background: var(--success); color: #fff; }
.btn-google {
    background: #fff;
    color: #3c4043;
    border: 1.5px solid #dadce0;
    box-shadow: 0 2px 6px rgba(0,0,0,.08);
    font-size: 0.9rem;
    padding: 0.7rem 1.4rem;
}
.btn-google:hover { box-shadow: 0 3px 10px rgba(0,0,0,.14); }

/* ─── FORM ──────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: .04em; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

.input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.875rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    appearance: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.input::placeholder { color: var(--text-muted); }
textarea.input { resize: vertical; min-height: 80px; }
select.input { cursor: pointer; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

/* ─── MODAL ─────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateY(24px) scale(.97);
    transition: transform 0.25s ease;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal.large { max-width: 760px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-body { overflow-y: auto; padding: 1.5rem; flex: 1; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ─── QUOTE ITEMS TABLE ─────────────────────────────── */
.items-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.5rem; }
.items-table th { background: var(--surface2); padding: 0.5rem 0.625rem; text-align: left; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.items-table td { padding: 0.5rem 0.625rem; border-bottom: 1px solid var(--border); }
.items-table tr:last-child td { border-bottom: none; }

.quote-summary {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.summary-row { display: flex; gap: 2rem; font-size: 0.875rem; }
.summary-row .label { color: var(--text-muted); }
.summary-row.total { font-size: 1rem; font-weight: 700; color: var(--primary); }

/* ─── TOAST ─────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease forwards;
    color: #fff;
    max-width: 320px;
    pointer-events: all;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }
.toast.warning { background: var(--warning); }
.toast.out { animation: toastOut 0.3s ease forwards; }

/* ─── STATUS BADGE ──────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
}
.badge.connected { background: #D1FAE5; color: #065F46; }
.badge.disconnected { background: #FEE2E2; color: #991B1B; }
[data-theme="dark"] .badge.connected { background: #064E3B; color: #6EE7B7; }
[data-theme="dark"] .badge.disconnected { background: #7F1D1D; color: #FCA5A5; }

/* ─── EMPTY STATE ───────────────────────────────────── */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 3rem 1rem; color: var(--text-muted); text-align: center; gap: 0.75rem;
}
.empty-state svg { opacity: .3; }
.empty-state p { font-size: 0.875rem; }

/* ─── ANIMATIONS ─────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastIn { from { opacity:0; transform: translateX(40px); } to { opacity:1; transform: translateX(0); } }
@keyframes toastOut { from { opacity:1; transform: translateX(0); } to { opacity:0; transform: translateX(40px); } }

/* ─── UTILITIES ─────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-primary { color: var(--primary) !important; }

/* ─── RESPONSIVE ─────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .bottom-nav { display: block; }
    .content { padding: 1rem; padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .stat-value { font-size: 1.5rem; }
    .stat-label { font-size: 0.65rem; }
    .form-row { flex-direction: column; }
    .topbar { padding: 0 1rem; }
    .modal { max-width: 100%; max-height: 95dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    table { font-size: 0.8rem; }
    tbody td, thead th { padding: 0.6rem 0.5rem; }
    .quote-card { padding: 0.875rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .topbar h2 { font-size: 0.95rem; }
    #toast-container { left: 1rem; right: 1rem; bottom: calc(5rem + env(safe-area-inset-bottom)); }
    .toast { max-width: 100%; }
}
