/* ============================================================
   assets/css/app.css
   Single stylesheet for the entire application.
   Structure:
     1.  Reset & tokens
     2.  Typography
     3.  Layout
     4.  Header / nav / footer
     5.  Buttons
     6.  Badges / chips
     7.  Cards / tables
     8.  Forms
     9.  Modals
    10.  Login page
    11.  Utilities
    12.  Responsive
   ============================================================ */

/* ------------------------------------------------------------
   1. RESET & TOKENS
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

:root {
    /* Brand */
    --primary:       #3b82f6;
    --primary-h:     #2563eb;
    --primary-soft:  #eff6ff;
    --success:       #10b981;
    --success-h:     #059669;
    --warning:       #f59e0b;
    --warning-h:     #d97706;
    --danger:        #cc3106;
    --danger-h:      #a32705;

    /* Surfaces */
    --bg:            #f8fafc;
    --bg-alt:        #f1f5f9;
    --card:          #ffffff;

    /* Text */
    --text:          #0f172a;
    --text-soft:     #334155;
    --muted:         #64748b;
    --muted-2:       #94a3b8;

    /* Borders */
    --border:        #e2e8f0;
    --border-strong: #cbd5e1;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    /* Radii */
    --radius-xs:  6px;
    --radius-sm:  8px;
    --radius-md:  12px;
    --radius-lg:  16px;
    --radius-xl:  20px;
    --radius-pill: 40px;

    /* Sizing */
    --header-h: 64px;
    --header-h-mobile: 56px;

    /* Typography */
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}


/* ------------------------------------------------------------
   2. TYPOGRAPHY
   ------------------------------------------------------------ */
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-h); }

strong { font-weight: 700; }
code, kbd, pre {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.9em;
}


/* ------------------------------------------------------------
   3. LAYOUT
   ------------------------------------------------------------ */
.app-main {
    flex: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}


/* ------------------------------------------------------------
   4. HEADER / NAV / FOOTER
   ------------------------------------------------------------ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}
.app-header-inner {
    max-width: 1400px;
    margin: 0 auto;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
}

/* Brand */
.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    flex-shrink: 0;
}
.app-brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.app-brand-text { display: flex; flex-direction: column; min-width: 0; }
.app-brand-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    line-height: 1.1;
    white-space: nowrap;
}
.app-brand-sub {
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Nav */
.app-nav {
    display: flex;
    gap: 4px;
    margin-left: 24px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.app-nav::-webkit-scrollbar { display: none; }
.app-nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    color: var(--muted);
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.app-nav-link:hover { background: var(--bg-alt); color: var(--text); }

/* Actions */
.app-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Footer */
.app-footer {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px 20px;
    color: var(--muted);
    font-size: 0.8rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Hamburger */
.app-icon-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.app-icon-btn:hover { background: var(--bg-alt); }


/* ------------------------------------------------------------
   5. BUTTONS
   ------------------------------------------------------------ */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(59,130,246,0.25);
    line-height: 1.2;
}
.app-btn:hover {
    background: var(--primary-h);
    transform: translateY(-1px);
    color: #fff;
}
.app-btn:active { transform: translateY(0); }
.app-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Variants */
.app-btn-primary { background: var(--primary); }
.app-btn-primary:hover { background: var(--primary-h); }

.app-btn-success {
    background: var(--success);
    box-shadow: 0 2px 6px rgba(16,185,129,0.25);
}
.app-btn-success:hover { background: var(--success-h); }

.app-btn-warning {
    background: var(--warning);
    box-shadow: 0 2px 6px rgba(245,158,11,0.25);
}
.app-btn-warning:hover { background: var(--warning-h); }

.app-btn-danger {
    background: var(--danger);
    box-shadow: 0 2px 6px rgba(204,49,6,0.25);
}
.app-btn-danger:hover { background: var(--danger-h); }

.app-btn-ghost {
    background: var(--bg-alt);
    color: var(--text);
    box-shadow: none;
}
.app-btn-ghost:hover { background: var(--border); color: var(--text); }

.app-btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    box-shadow: none;
}
.app-btn-outline:hover { background: var(--primary-soft); }

.app-btn-cache {
    background: var(--warning);
    color: #fff;
    box-shadow: 0 2px 6px rgba(245,158,11,0.25);
}
.app-btn-cache:hover { background: var(--warning-h); }

/* Sizes */
.app-btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.app-btn-lg { padding: 12px 24px; font-size: 0.95rem; }


/* ------------------------------------------------------------
   6. BADGES / CHIPS
   ------------------------------------------------------------ */
.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    background: var(--bg-alt);
    color: var(--text-soft);
}

.app-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg-alt);
    color: var(--text-soft);
    border: 1px solid var(--border);
    transition: background 0.15s, border-color 0.15s;
}
.app-chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Flash toast */
.app-flash {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: 0 6px 20px rgba(16,185,129,0.4);
    z-index: 9999;
}


/* ------------------------------------------------------------
   7. CARDS / TABLES
   ------------------------------------------------------------ */
.app-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}

.app-list-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    padding: 16px;
    margin-bottom: 12px;
    border-left: 5px solid transparent;
}

/* Tables */
.app-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-md);
    -webkit-overflow-scrolling: touch;
}
.app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 720px;
}
.app-table th,
.app-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.app-table th {
    background: var(--bg-alt);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
}
.app-table tbody tr:hover { background: var(--bg); }
.app-table tbody tr:last-child td { border-bottom: none; }


/* ------------------------------------------------------------
   8. FORMS
   ------------------------------------------------------------ */
.app-form-group { margin-bottom: 14px; }
.app-form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-soft);
    margin-bottom: 4px;
}
.app-form-group input,
.app-form-group select,
.app-form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--card);
    color: var(--text);
    transition: border 0.15s, box-shadow 0.15s;
}
.app-form-group input:focus,
.app-form-group select:focus,
.app-form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.app-form-group textarea {
    min-height: 70px;
    resize: vertical;
}

.app-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.app-form-grid .full { grid-column: span 2; }

.app-form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}


/* ------------------------------------------------------------
   9. MODALS
   ------------------------------------------------------------ */
.app-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    display: none;
    justify-content: center;
    align-items: center;
    padding: 16px;
    z-index: 2000;
    overflow-y: auto;
}
.app-overlay.open { display: flex; }

.app-modal {
    background: var(--card);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 620px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 22px;
    box-shadow: var(--shadow-lg);
    -webkit-overflow-scrolling: touch;
}

.app-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.app-modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
    word-break: break-word;
}
.app-modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0 6px;
    border-radius: var(--radius-sm);
    transition: color 0.15s;
    flex-shrink: 0;
}
.app-modal-close:hover { color: var(--danger); }

/* Detail grid inside modals */
.app-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.app-detail-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    min-width: 0;
}
.app-detail-item.full { grid-column: span 2; }
.app-detail-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 3px;
}
.app-detail-value {
    font-size: 0.9rem;
    color: var(--text);
    font-weight: 500;
    word-break: break-word;
    line-height: 1.35;
}


/* ------------------------------------------------------------
   10. LOGIN PAGE
   ------------------------------------------------------------ */
.login-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(145deg, #0B5345 0%, #148F77 100%);
}

.login-card {
    background: var(--card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 30px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}
.login-card h1 {
    font-size: 1.6rem;
    margin-bottom: 6px;
}
.login-subtitle {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}
.login-card input[type="password"] {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    text-align: center;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text);
    margin-bottom: 15px;
}
.login-card input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
    background: #fff;
}
.login-card button {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.login-card button:hover {
    background: var(--primary-h);
    transform: translateY(-1px);
}
.login-error {
    color: var(--danger);
    font-weight: 600;
    margin-bottom: 12px;
    font-size: 0.9rem;
}
.login-footer {
    margin-top: 20px;
    color: rgba(255,255,255,0.7);
    font-size: 0.75rem;
}


/* ------------------------------------------------------------
   11. UTILITIES
   ------------------------------------------------------------ */
.hidden { display: none !important; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }

.mt-1 { margin-top: 8px; }   .mt-2 { margin-top: 16px; }   .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.p-1  { padding: 8px; }      .p-2  { padding: 16px; }      .p-3  { padding: 24px; }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 8px; }   .gap-2 { gap: 16px; }   .gap-3 { gap: 24px; }

.full-width { width: 100%; }


/* ------------------------------------------------------------
   12. RESPONSIVE
   ------------------------------------------------------------ */
@media (max-width: 900px) {
    .app-header-inner {
        padding: 0 12px;
        height: var(--header-h-mobile);
        gap: 8px;
    }
    .app-nav {
        display: none;
        position: absolute;
        top: var(--header-h-mobile);
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        padding: 8px 0;
        margin-left: 0;
        max-height: calc(100vh - var(--header-h-mobile));
        overflow-y: auto;
    }
    .app-nav.open { display: flex; }
    .app-nav-link {
        padding: 12px 20px;
        border-radius: 0;
        font-size: 0.9rem;
    }
    .app-icon-btn { display: block; }
    .app-brand-sub { display: none; }
    .app-main { padding: 12px; }
    .app-footer { padding: 12px; font-size: 0.75rem; }

    .app-form-grid { grid-template-columns: 1fr; }
    .app-form-grid .full { grid-column: span 1; }
    .app-detail-grid { grid-template-columns: 1fr; }
    .app-detail-item.full { grid-column: span 1; }
}

@media (max-width: 600px) {
    body { font-size: 0.95rem; }
    h1 { font-size: 1.35rem; }
    h2 { font-size: 1.15rem; }
    h3 { font-size: 1rem; }

    .app-card { padding: 14px; border-radius: var(--radius-md); }
    .app-modal {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        align-self: flex-end;
        max-height: 92vh;
        padding: 18px 16px;
    }
    .app-overlay { align-items: flex-end; padding: 0; }

    .app-btn { padding: 8px 14px; font-size: 0.82rem; }
    .app-btn-sm { padding: 6px 10px; font-size: 0.75rem; }

    .app-table { font-size: 0.8rem; }
    .app-table th, .app-table td { padding: 8px 10px; }
}

@media (max-width: 400px) {
    .app-brand-title { font-size: 0.9rem; }
    .app-brand-mark { width: 36px; height: 36px; font-size: 0.8rem; }
    .app-header-actions .app-btn { padding: 7px 12px; font-size: 0.75rem; }
}

/* ---------- Dark mode (optional, respects OS) ---------- */
@media (prefers-color-scheme: dark) {
    /* Uncomment to enable
    :root {
        --bg:     #0f172a;
        --card:   #1e293b;
        --text:   #f1f5f9;
        --border: #334155;
        --muted:  #94a3b8;
    }
    */
}

/* ---------- Print ---------- */
@media print {
    .app-header,
    .app-footer,
    .app-btn,
    .app-icon-btn,
    .app-modal,
    .app-overlay { display: none !important; }

    body { background: #fff; color: #000; }
    .app-main { padding: 0; max-width: 100%; }
    .app-card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
    a { color: #000; text-decoration: underline; }
}