
:root {
    --primary: #ff7a00;
    --primary-dark: #e56e00;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --success: #198754;
    --danger: #dc3545;
    --sidebar: #111827;
    --sidebar-text: #f9fafb;
    --shadow-sm: 0 10px 25px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 20px 45px rgba(15, 23, 42, 0.12);
    --shadow-lg: 0 30px 70px rgba(15, 23, 42, 0.16);
    --radius: 18px;
    --transition: all 0.25s ease;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(255, 122, 0, 0.12), transparent 30%),
        radial-gradient(circle at bottom right, rgba(13, 202, 240, 0.1), transparent 25%),
        linear-gradient(135deg, #f8fbff 0%, #eef4fb 45%, #f4f7fb 100%);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover { color: var(--primary-dark); }

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 16px;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(229,231,235,0.9);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    padding: 34px 28px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), #ff9f45);
    color: #fff;
    font-weight: 700;
    font-size: 24px;
    box-shadow: 0 14px 30px rgba(255, 122, 0, 0.28);
}

.auth-brand h1 { margin: 0 0 6px; }
.auth-brand p { margin: 0; color: var(--muted); }

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

label {
    font-size: 14px;
    font-weight: 600;
}

input, select, textarea {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 14px;
    background: #fff;
    outline: none;
    transition: var(--transition);
}

input[type="radio"], input[type="checkbox"] {
    width: auto;
    padding: 0;
    border-radius: 0;
    accent-color: #f97316;
    flex-shrink: 0;
}

.option-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 400;
    margin-bottom: 8px;
    background: #fff;
    transition: border-color .15s, background .15s;
}

.option-label:hover {
    border-color: #f97316;
    background: #fff7ed;
}

.option-label input[type="radio"],
.option-label input[type="checkbox"] {
    margin: 0;
}

textarea { min-height: 100px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    border-color: rgba(255, 122, 0, 0.7);
    box-shadow: 0 0 0 4px rgba(255, 122, 0, 0.12);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border: none;
    border-radius: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #ff9d3f);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-2px);
}

.btn-secondary {
    background: #eef2f7;
    color: var(--text);
}

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 18px;
    font-size: 14px;
}

.alert-success {
    background: rgba(25, 135, 84, 0.1);
    color: #146c43;
}

.alert-danger {
    background: rgba(220, 53, 69, 0.1);
    color: #b42318;
}

.alert-error {
    background: rgba(220, 53, 69, 0.1);
    color: #b42318;
}

.auth-note {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(255, 122, 0, 0.08);
    color: #4b5563;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    /* No overflow:hidden — causes interaction blocking */
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #f1f5f9;
}

.sidebar-brand span {
    display: block;
    font-size: 11px;
    color: #94a3b8;
}

.sidebar nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar nav a {
    display: block;
    padding: 9px 12px;
    border-radius: 8px;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.sidebar nav a:hover { background: #334155; color: #e2e8f0; }
.sidebar nav a.active { background: rgba(249,115,22,0.15); color: #f97316; font-weight: 600; }
.tt-nav-logout {
    display: block;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    color: #fca5a5 !important;
}
.tt-nav-logout:hover { color: #ef4444 !important; background: rgba(239,68,68,0.08) !important; }

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
    padding: 24px;
    overflow-y: auto;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.page-title h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    color: #0f172a;
}

.page-title p {
    margin: 2px 0 0;
    font-size: 12px;
    color: #64748b;
}

.user-badge {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 18px;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 14px;
}

.stat-value {
    font-size: 30px;
    font-weight: 700;
}

.stat-label {
    color: var(--muted);
    font-size: 14px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th, table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: top;
}

table th {
    background: #fafbfd;
    color: var(--muted);
    font-weight: 700;
}

.list-clean {
    list-style: none;
    margin: 0;
    padding: 0;
}

.list-clean li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge-success {
    background: rgba(25, 135, 84, 0.12);
    color: #146c43;
}


/* ═══ Responsive ═══ */
@media (max-width: 900px) {
    .content-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .grid-cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

@media (max-width: 768px) {
    /* Stack layout vertically */
    .app-shell  { flex-direction: column; overflow: visible; }
    .app-main   { height: auto; overflow-y: visible; }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 12px 16px;
        overflow-y: visible;
    }
    .sidebar-brand, .brand-block {
        display: flex; align-items: center; justify-content: space-between;
        width: 100%; margin-bottom: 0;
    }
    #tt-nav-toggle {
        display: inline-flex; align-items: center; gap: 6px;
        background: rgba(255,255,255,0.08); color: inherit; border: 1px solid rgba(255,255,255,0.15);
        border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
    }
    .sidebar nav {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 2px;
        margin-top: 12px;
        max-height: 60vh;
        overflow-y: auto;
    }
    .sidebar nav.tt-nav-open { display: flex; }
    .sidebar nav a, .sidebar-nav, .nav-link {
        display: block; width: 100%; box-sizing: border-box;
        padding: 11px 14px; border-radius: 8px;
    }
    .sb-footer { width: 100%; margin-top: 10px; }

    /* Topbar no longer clashes — it's in normal flow */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 14px 16px;
        margin-bottom: 14px;
        border-radius: 12px;
    }
    .page-title h1 { font-size: 18px; }
    .page-title p  { font-size: 13px; margin-top: 4px; }
    .user-badge, .user-chip { width: 100%; box-sizing: border-box; }
    .main-content, .content { padding: 12px; }
    .stat-value  { font-size: 22px; }
    .card        { padding: 14px; }
    .grid-cards  { grid-template-columns: 1fr 1fr; gap: 12px; }
    table th, table td { padding: 10px 8px; font-size: 13px; }
}

@media (min-width: 769px) {
    #tt-nav-toggle { display: none; }
}

@media (max-width: 480px) {
    .grid-cards  { grid-template-columns: 1fr; }
    .topbar      { padding: 12px 14px; }
    .page-title h1 { font-size: 16px; }
}
/* ── PWA & Mobile Responsive Enhancements ── */
@media (max-width: 640px) {
    .main-content { padding: 12px !important; }
    .topbar { padding: 0 12px !important; height: auto !important; min-height: 56px; flex-wrap: wrap; gap: 8px; padding-top: 8px !important; padding-bottom: 8px !important; }
    .page-title h1 { font-size: 16px !important; }
    .user-badge { font-size: 11px; }
    .card { padding: 14px !important; border-radius: 10px !important; }
    .form-row { grid-template-columns: 1fr !important; }
    .grid-cards { grid-template-columns: 1fr 1fr !important; }
    table { font-size: 12px; }
    th, td { padding: 8px 6px !important; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .btn, .btn-primary, .btn-secondary { padding: 10px 16px !important; font-size: 13px !important; }
    .sidebar { width: 100% !important; }
    .app-shell { flex-direction: column !important; }
    .stat-value { font-size: 28px !important; }
}

@media (max-width: 400px) {
    .grid-cards { grid-template-columns: 1fr !important; }
    .plan-cards { grid-template-columns: 1fr !important; }
}

/* PWA safe areas */
@supports (padding: env(safe-area-inset-bottom)) {
    .main-content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
    .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* Improve touch targets */
.sidebar nav a { min-height: 44px; display: flex; align-items: center; }
button, .btn, a.btn { min-height: 40px; }

/* Smooth scrolling */
html { scroll-behavior: smooth; }
* { -webkit-tap-highlight-color: transparent; }

/* ── Pass 4 & 5: UX Improvements — engagement, accessibility, convenience ── */

/* Smooth page transitions */
.main-content { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Better focus states for keyboard nav */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid #f97316;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Sticky top bar */
.topbar { position: sticky; top: 0; z-index: 100; backdrop-filter: blur(8px); }

/* Card hover lift */
.card { transition: box-shadow .2s, transform .2s; }
.card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.08); }

/* Better table rows */
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fff8f3; }

/* Active nav highlight pulse */
.sidebar nav a.active { animation: none; }
.sidebar nav a.active::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 60%; background: #f97316; border-radius: 0 2px 2px 0; }
.sidebar nav a { position: relative; }

/* Badge count animation */
.badge { animation: popIn .2s cubic-bezier(.175,.885,.32,1.275); }
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

/* Toasts / flash messages improvement */
.alert, .alert-success, .alert-danger, .alert-error {
    animation: slideDown .25s ease;
    border-radius: 10px;
}
@keyframes slideDown { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Better empty states */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #94a3b8;
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: #475569; margin: 0 0 6px; }
.empty-state p { font-size: 13px; }

/* Progress bar component */
.progress-bar { background: #e2e8f0; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: #f97316; border-radius: 999px; transition: width .4s ease; }

/* Chip / tag component */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #f1f5f9; color: #475569; }
.chip.chip-green { background: #f0fdf4; color: #166534; }
.chip.chip-red { background: #fef2f2; color: #b91c1c; }
.chip.chip-blue { background: #eff6ff; color: #1d4ed8; }
.chip.chip-orange { background: #fff7ed; color: #c2410c; }

/* Floating action button for mobile */
.fab {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: #f97316;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(249,115,22,.4);
    z-index: 200;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(249,115,22,.5); }

/* PWA & Mobile */
@media (max-width: 768px) {
    .fab { display: flex; }
    .main-content { padding: 12px !important; }
    .card { padding: 14px !important; border-radius: 10px !important; }
    .form-row { grid-template-columns: 1fr !important; }
    .grid-cards { grid-template-columns: 1fr 1fr !important; }
    table { font-size: 12px; }
    th, td { padding: 8px 6px !important; }
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .topbar { padding: 0 12px !important; }
    .page-title h1 { font-size: 16px !important; }
    .sidebar nav a span.nav-label { display: none; }
}
@media (max-width: 480px) {
    .grid-cards { grid-template-columns: 1fr !important; }
}

/* Skeleton loading shimmer for cards */
.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Tooltip */
[data-tip] { position: relative; cursor: help; }
[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: #1e293b; color: #f8fafc; font-size: 11px; padding: 4px 8px; border-radius: 5px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .15s; z-index: 99; }
[data-tip]:hover::after { opacity: 1; }

/* Safe area support for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .main-content { padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important; }
    .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

/* Print improvements */
@media print {
    .sidebar, .topbar, .no-print, .fab, .alert { display: none !important; }
    .main-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #e2e8f0 !important; }
    a { color: inherit !important; text-decoration: none !important; }
}

html { scroll-behavior: smooth; }
* { -webkit-tap-highlight-color: transparent; }
