/* ============================================================
   assets/css/app.css
   Emerald green theme. Mobile-first. Complete stylesheet.
   ============================================================ */

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

html,
body {
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg, #f0fdf4);
    color: var(--text, #0f172a);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

h1 { font-size: 1.5rem; font-weight: 600; color: var(--text); }
h2 { font-size: 1.25rem; font-weight: 600; color: var(--text); }
h3 { font-size: 1.05rem; font-weight: 600; color: var(--text); }
h4 { font-size: 0.95rem; font-weight: 600; color: var(--text); }

a { color: var(--primary, #059669); text-decoration: none; }
a:hover { color: var(--primary-h, #047857); }

/* ============================================================
   HEADER / TOP NAV
   ============================================================ */

.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--surface, #ffffff);
    border-bottom: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.app-header-inner {
    max-width: 1600px;
    margin: 0 auto;
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    position: relative;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
}

.app-brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--primary, #059669);
    color: #ffffff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.app-brand-title {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    color: var(--text);
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: 16px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible;
}

.app-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--muted, #475569);
    font-weight: 500;
    font-size: 0.85rem;
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.app-nav-link:hover,
.app-nav-link:focus-visible {
    background: var(--primary-light, #d1fae5);
    color: var(--primary-dark, #065f46);
    outline: none;
}

.app-nav-link.active {
    background: var(--primary-light, #d1fae5);
    color: var(--primary-dark, #065f46);
    font-weight: 600;
}

.app-nav-link .nav-ico { font-size: 1rem; line-height: 1; }
.app-nav-link .nav-lbl { display: inline-block; }
.app-nav-link .nav-caret { font-size: 0.7rem; opacity: 0.7; }

.app-nav-group { position: relative; flex-shrink: 0; }

.app-nav-sub {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: #ffffff;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 2000;
    margin-top: 6px;
}

.app-nav-group.open .app-nav-sub { display: block; }

.app-nav-sub a {
    display: block;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.app-nav-sub a:hover {
    background: var(--primary-light, #d1fae5);
    color: var(--primary-dark, #065f46);
}

.app-user {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    font-size: 0.82rem;
    margin-left: 8px;
}

.app-user-name { color: var(--muted, #475569); white-space: nowrap; }

.app-user-out {
    color: var(--danger, #ef4444);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.app-user-out:hover { text-decoration: underline; }

.app-icon-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: 8px;
    margin-left: auto;
    flex-shrink: 0;
    font-family: inherit;
}

.app-icon-btn:hover { background: var(--primary-light, #d1fae5); }

/* ============================================================
   LAYOUT
   ============================================================ */

.app-main {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px;
}

.app-card {
    background: var(--surface, #ffffff);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border, #e2e8f0);
    padding: 16px;
    margin-bottom: 16px;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 40px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    text-decoration: none;
    background: var(--primary, #059669);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
    transition: background 0.15s, transform 0.15s;
}

.app-btn:hover {
    background: var(--primary-h, #047857);
    transform: translateY(-1px);
}

.app-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.app-btn-success { background: var(--success, #10b981); }
.app-btn-success:hover { background: #059669; }

.app-btn-danger { background: var(--danger, #ef4444); }
.app-btn-danger:hover { background: #dc2626; }

.app-btn-ghost {
    background: #f1f5f9;
    color: var(--text);
    box-shadow: none;
}

.app-btn-ghost:hover { background: #e2e8f0; }

.app-btn-sm { padding: 6px 12px; font-size: 0.78rem; }

/* ============================================================
   BADGES / CHIPS
   ============================================================ */

.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 40px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.app-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 40px;
    font-size: 0.72rem;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
}

.app-chip.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* ============================================================
   TABLES
   ============================================================ */

.app-table-wrap {
    overflow-x: auto;
    border-radius: 12px;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 680px;
}

.app-table th,
.app-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border, #e2e8f0);
}

.app-table th {
    background: #f8fafc;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.app-table tbody tr:hover { background: #f8fafc; }

/* ============================================================
   FORMS
   ============================================================ */

.app-form-group { margin-bottom: 12px; }

.app-form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.78rem;
    margin-bottom: 4px;
    color: #334155;
}

.app-form-group input,
.app-form-group select,
.app-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong, #cbd5e1);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.88rem;
    background: #ffffff;
    color: var(--text);
}

.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(5, 150, 105, 0.15);
}

.app-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.app-form-grid .full { grid-column: span 1; }

@media (min-width: 640px) {
    .app-form-grid { grid-template-columns: 1fr 1fr; }
    .app-form-grid .full { grid-column: span 2; }
}

/* ============================================================
   MODALS
   ============================================================ */

.app-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 14px;
    overflow-y: auto;
}

.app-overlay.open { display: flex; }

.app-modal {
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 18px;
    touch-action: pan-y;
}

.app-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.app-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
}

.app-detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.app-detail-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
}

.app-detail-item.full { grid-column: span 1; }

.app-detail-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 2px;
}

.app-detail-value {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 500;
    word-break: break-word;
}

@media (min-width: 640px) {
    .app-detail-grid { grid-template-columns: 1fr 1fr; }
    .app-detail-item.full { grid-column: span 2; }
}

/* ============================================================
   PROGRAM CARDS
   ============================================================ */

.prog-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.prog-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border);
    border-left: 5px solid var(--primary);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prog-card .prog-name {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
}

.prog-card .prog-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 0.82rem;
    color: var(--muted);
}

.prog-card .prog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    background: linear-gradient(135deg, #065f46 0%, #059669 100%);
    margin: 0;
}

.login-card {
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h1 {
    font-size: 1.4rem;
    margin-bottom: 4px;
    color: #065f46;
}

.login-subtitle {
    color: #64748b;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.login-card input {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    margin-bottom: 12px;
    font-family: inherit;
}

.login-card input:focus {
    outline: none;
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
    background: #ffffff;
}

.login-card button {
    width: 100%;
    padding: 13px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 40px;
    background: #059669;
    color: #ffffff;
    cursor: pointer;
    font-family: inherit;
}

.login-card button:hover { background: #047857; }

.login-error {
    color: #ef4444;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.85rem;
}

/* ============================================================
   UTILITIES
   ============================================================ */

.hidden { display: none !important; }
.text-muted { color: var(--muted, #475569); }
.text-center { text-align: center; }
.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; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (min-width: 768px) {
    .app-main { padding: 20px; }
    .app-header-inner { padding: 0 20px; min-height: 64px; }
}

@media (max-width: 900px) and (min-width: 601px) {
    .app-brand-title { display: none; }
    .app-nav { margin-left: 8px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
    .app-nav::-webkit-scrollbar { display: none; }
    .app-nav-link { padding: 8px 10px; }
    .app-nav-link .nav-lbl { display: none; }
    .app-nav-link .nav-ico { font-size: 1.15rem; }
    .app-nav-link .nav-caret { display: none; }
    .app-user-name { display: none; }
}

@media (max-width: 600px) {
    .app-header-inner {
        gap: 8px;
        padding: 0 8px;
        flex-wrap: nowrap;
    }

    .app-icon-btn { display: inline-flex; }

    .app-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: #ffffff;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
        padding: 8px;
        margin: 0;
        gap: 0;
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 1500;
        flex: none;
    }

    .app-nav.open { display: flex; }

    .app-nav-link {
        width: 100%;
        padding: 12px 14px;
        justify-content: flex-start;
    }

    .app-nav-link .nav-lbl { display: inline-block; }
    .app-nav-link .nav-caret { display: inline-block; margin-left: auto; }

    .app-nav-group { position: static; width: 100%; }

    .app-nav-sub {
        position: static;
        display: none;
        box-shadow: none;
        border: none;
        background: #f8fafc;
        margin: 0 0 6px 0;
        padding: 4px 0 4px 12px;
        border-left: 3px solid var(--primary-light, #d1fae5);
        border-radius: 0;
        min-width: 0;
    }

    .app-nav-group.open .app-nav-sub { display: block; }

    .app-user { margin-left: 0; }
    .app-user-name { display: none; }
    .app-user-out { font-size: 0.78rem; }
}