/* ==========================================================================
   Form 16 Manager — Application Stylesheet
   ========================================================================== */

:root {
    --ink: #1a2332;
    --ink-soft: #4a5568;
    --muted: #8a94a6;
    --border: #e2e6ee;
    --bg: #f4f6fb;
    --card: #ffffff;
    --primary: #2452c8;
    --primary-dark: #1a3d99;
    --primary-soft: #eaf0ff;
    --green: #1a9c6b;
    --green-soft: #e6f7ef;
    --amber: #b9790a;
    --amber-soft: #fff4e0;
    --red: #d63847;
    --red-soft: #fdecee;
    --blue: #2452c8;
    --blue-soft: #eaf0ff;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 4px 16px rgba(20, 30, 60, 0.05);
    font-size: 15px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

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

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0; }
.muted { color: var(--muted); margin: 0; }

/* ---------------- Topbar ---------------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 800;
    font-size: 0.75rem;
    padding: 6px 9px;
    border-radius: 8px;
    letter-spacing: 0.5px;
}
.brand-mark.lg { font-size: 1.1rem; padding: 12px 16px; border-radius: 12px; }
.brand-text { font-size: 1.05rem; }
.topnav { display: flex; gap: 6px; flex: 1; }
.topnav a { color: var(--ink-soft); padding: 8px 14px; border-radius: 8px; font-weight: 500; font-size: 0.92rem; }
.topnav a:hover { background: var(--bg); text-decoration: none; }
.topnav a.active { background: var(--primary-soft); color: var(--primary-dark); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 0.88rem; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.user-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.user-chip small { color: var(--muted); }

/* ---------------- Layout ---------------- */
.page-wrap { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.app-footer { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 24px; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 8px; padding: 10px 18px;
    font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: all .15s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); }
.btn-secondary:hover { background: #dbe6ff; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--card); border-color: var(--muted); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b52a38; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- Stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
    border-left: 4px solid var(--primary);
}
.stat-card.accent-green { border-left-color: var(--green); }
.stat-card.accent-amber { border-left-color: var(--amber); }
.stat-card.accent-blue { border-left-color: var(--blue); }
.stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 1.55rem; font-weight: 700; }

/* ---------------- Panel / cards ---------------- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; margin: 0 0 18px; box-shadow: var(--shadow);
}
.card legend { font-weight: 700; padding: 0 6px; color: var(--primary-dark); font-size: 0.95rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ---------------- Filter bar ---------------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input[type="text"] { flex: 1; min-width: 220px; }
.filter-bar input, .filter-bar select {
    padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; background: #fff;
}

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; padding: 10px 12px; background: var(--bg); color: var(--ink-soft); font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: #fafbfe; }
.text-right { text-align: right; }
.center { text-align: center; }
.empty-row { text-align: center; padding: 40px !important; color: var(--muted); }

.actions-cell { white-space: nowrap; }
.icon-btn { border: 1px solid var(--border); background: #fff; border-radius: 6px; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; margin-left: 4px; cursor: pointer; font-size: 0.95rem; }
.icon-btn:hover { background: var(--bg); text-decoration: none; }
.icon-btn-danger:hover { background: var(--red-soft); border-color: var(--red); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }

.editable-table input { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 0.88rem; }
.editable-table tfoot td { background: var(--bg); font-weight: 700; }

/* ---------------- Forms ---------------- */
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 12px; }
label.readonly-row { display: flex; justify-content: space-between; align-items: center; }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="password"], select {
    width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.92rem; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.hint { font-size: 0.78rem; color: var(--muted); margin: -6px 0 10px; }

.calc-out { font-weight: 700; color: var(--primary-dark); }
.calc-out.lg { font-size: 1.3rem; }
.calc-summary { text-align: right; padding: 14px 20px; background: var(--primary-soft); border-radius: var(--radius); font-weight: 600; }

.calc-table { width: 100%; border-collapse: collapse; }
.calc-table td { padding: 9px 6px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.calc-table td:last-child { text-align: right; font-weight: 600; }
.calc-table .row-strong td { font-weight: 700; background: var(--bg); }
.calc-table .row-final td { font-weight: 800; background: var(--primary-soft); color: var(--primary-dark); font-size: 1.05rem; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tab-btn {
    background: none; border: none; padding: 10px 16px; font-size: 0.88rem; font-weight: 600; color: var(--muted);
    cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Alerts ---------------- */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 0.88rem; margin-bottom: 16px; }
.alert-error { background: var(--red-soft); color: var(--red); border: 1px solid #f6c6cb; }
.alert-success { background: var(--green-soft); color: var(--green); border: 1px solid #b9e6cf; }
.alert-info { background: var(--blue-soft); color: var(--primary-dark); border: 1px solid #c9d8ff; }

/* ---------------- Auth pages ---------------- */
.auth-body { background: linear-gradient(160deg, #eef2fb, #f7f9fd); min-height: 100vh; display: flex; align-items: center; justify-content: center; margin: 0; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 40px; width: 380px; max-width: 92vw; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 1.3rem; margin: 12px 0 4px; }
.auth-brand p { color: var(--muted); font-size: 0.85rem; margin: 0; }
.auth-form label { text-align: left; }
.auth-hint { text-align: center; font-size: 0.83rem; color: var(--muted); margin-top: 14px; }
.auth-hint code { background: var(--bg); padding: 2px 6px; border-radius: 4px; }

/* ---------------- Popup / toast / modal system ---------------- */
#popup-root { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }
.toast-stack { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
    pointer-events: auto; min-width: 280px; max-width: 360px; background: #fff; border-left: 4px solid var(--primary);
    border-radius: 8px; box-shadow: var(--shadow); padding: 14px 16px; font-size: 0.88rem; display: flex; gap: 10px;
    align-items: flex-start; animation: slidein .2s ease;
}
.toast.toast-success { border-left-color: var(--green); }
.toast.toast-error { border-left-color: var(--red); }
.toast-icon { font-size: 1.1rem; }
.toast-close { margin-left: auto; cursor: pointer; color: var(--muted); background: none; border: none; font-size: 1rem; }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(20, 25, 40, 0.5); display: flex; align-items: center; justify-content: center;
    pointer-events: auto; animation: fadein .15s ease; z-index: 1001;
}
.modal-box { background: #fff; border-radius: 12px; padding: 24px; width: 380px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal-box h3 { margin: 0 0 8px; font-size: 1.05rem; }
.modal-box p { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .topbar-inner { flex-wrap: wrap; }
}
