:root {
    --bg: #0f1419;
    --sidebar: #151b23;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --border: #e2e8f0;
    --success: #16a34a;
    --danger: #dc2626;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: #f1f5f9;
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar), #0b1016);
    color: #e2e8f0;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0 0.5rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.brand small { color: #94a3b8; display: block; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav a {
    color: #cbd5e1;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    text-decoration: none;
}

.nav a:hover,
.nav a.active {
    background: rgba(14, 165, 233, 0.15);
    color: #fff;
}

.nav a.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.sidebar-footer {
    margin-top: auto;
    padding: 0.75rem;
    font-size: 0.9rem;
    color: #94a3b8;
}

.link-btn {
    background: none;
    border: none;
    color: #7dd3fc;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.main {
    padding: 1.5rem 2rem 3rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header h1 { margin: 0; font-size: 1.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}

.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.5rem; display: block; margin-top: 0.25rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    text-decoration: none;
}

.btn:hover { background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.toolbar input[type="search"] {
    flex: 1;
    max-width: 360px;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.table-spaced { margin-top: 1.5rem; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge-open, .badge-draft { background: #e0f2fe; color: #0369a1; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-overdue { background: #fee2e2; color: #b91c1c; }
.badge-cancelled { background: #f1f5f9; color: #475569; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-error ul { margin: 0; padding-left: 1.2rem; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 1rem; }
.form-section h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.checkbox { flex-direction: row !important; align-items: center; }

.placeholder-hint {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 0.75rem;
}

.placeholder-hint code {
    background: #f1f5f9;
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    font-size: 0.82rem;
}

.card-muted {
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
}

.signature-preview {
    margin: 0.5rem 0 0;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
}

.html-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.html-editor-block {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.email-preview-box {
    margin-top: 0.5rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 80px;
}

.email-preview-box p { margin: 0 0 0.75rem; }
.email-preview-box p:last-child { margin-bottom: 0; }

.btn-danger {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.settings-shell {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.25rem;
    align-items: start;
}

.settings-nav {
    padding: 1rem;
    position: sticky;
    top: 1rem;
}

.settings-nav-title {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
}

.settings-nav nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.settings-nav a {
    display: block;
    padding: 0.45rem 0.65rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

.settings-nav a:hover { background: #f1f5f9; }
.settings-nav a.active { background: #e0f2fe; color: #0369a1; font-weight: 600; }

.content-editor {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    background: #fafbfc;
}

.editor-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.editor-label { font-weight: 600; }

.editor-tab-bar {
    display: flex;
    gap: 0.25rem;
    background: #e2e8f0;
    padding: 0.2rem;
    border-radius: 8px;
}

.editor-tab {
    border: none;
    background: transparent;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
    color: var(--muted);
}

.editor-tab.active {
    background: #fff;
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.editor-pane textarea {
    width: 100%;
    font: inherit;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.inline-form select {
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
}

@media (max-width: 900px) {
    .settings-shell { grid-template-columns: 1fr; }
    .settings-nav { position: static; }
}

.line-item {
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.line-actions { display: flex; align-items: end; }

.section-title { margin: 1.5rem 0 0.75rem; font-size: 1.1rem; }

.preview-totals {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 8px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.pagination {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}

.pagination .disabled {
    opacity: 0.5;
    pointer-events: none;
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 10; }
    .form-grid { grid-template-columns: 1fr; }
}

.auth-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0ea5e9 120%);
    padding: 1.5rem;
}

.auth-shell { width: 100%; max-width: 420px; }

.auth-brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-bottom: 1.25rem;
}

.auth-brand small { color: #94a3b8; display: block; }

.auth-card { padding: 1.5rem; }

.auth-card label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.auth-card .btn-primary { width: 100%; margin-top: 0.5rem; }

.auth-card a { color: var(--primary-dark); }

/* iPhone / PWA */
.app-body {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.main {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0));
}

.mobile-only { display: none; }

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
    padding: 0.35rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom, 0));
    background: rgba(15, 20, 25, 0.96);
    border-top: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(12px);
}

.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.25rem;
    border-radius: 10px;
    color: #94a3b8;
    font-size: 0.68rem;
    text-decoration: none;
}

.bottom-nav a.active { color: #fff; background: rgba(14,165,233,0.2); }
.bottom-nav .bn-primary {
    color: #fff;
    background: var(--primary);
    font-weight: 600;
}
.bottom-nav .bn-icon { font-size: 1.15rem; line-height: 1; }

.tab-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.tab-bar a {
    flex: 1;
    text-align: center;
    padding: 0.65rem;
    border-radius: 10px;
    background: #e2e8f0;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}
.tab-bar a.active { background: var(--primary); color: #fff; }

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    margin-bottom: 1rem;
}
.stat-card.highlight { border: 2px solid var(--primary); }

.quick-hours {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.btn-lg {
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
    min-height: 48px;
}

.btn.full { width: 100%; }

.invoice-from-hours { margin-top: 1rem; }

.mobile-form input,
.mobile-form select,
.mobile-form textarea,
.mobile-form button {
    font-size: 16px;
}

@media (max-width: 900px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: grid; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main { padding: 1rem 1rem 6rem; }
    .page-header { flex-direction: column; align-items: stretch; gap: 0.75rem; }
    .header-actions { flex-wrap: wrap; }
    .header-actions .btn { flex: 1 1 auto; min-height: 44px; }
    .summary-cards { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .settings-shell { grid-template-columns: 1fr; }
    .table-hours { font-size: 0.85rem; }
    .table-hours .btn-sm { min-width: 44px; min-height: 44px; }
}
