/* KPI Grading System (kpica) — Plain CSS, no preprocessor */

:root {
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-primary: #1a56db;
    --color-primary-dark: #1e40af;
    --color-success: #059669;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: 14px;
}

/* ── Navigation ─────────────────────────────────────────────── */
.navbar {
    background: var(--color-primary);
    color: #fff;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 52px;
    box-shadow: var(--shadow-md);
}

.navbar .logo {
    font-size: 1.1rem;
    font-weight: 700;
    margin-right: 2rem;
    white-space: nowrap;
}

.navbar .nav-tabs {
    display: flex;
    gap: 0;
    flex: 1;
    list-style: none;
}

.navbar .nav-tabs a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 0.6rem 1rem;
    display: block;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.15s;
}

.navbar .nav-tabs a:hover,
.navbar .nav-tabs a.active {
    color: #fff;
    border-bottom-color: #fff;
}

.navbar .user-info {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar .user-info a {
    color: #fff;
    text-decoration: none;
    opacity: 0.8;
}
.navbar .user-info a:hover { opacity: 1; }

/* ── Layout ─────────────────────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

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

.page-header h1 {
    font-size: 1.3rem;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}

/* ── Tables ─────────────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

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

th {
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
}

tbody tr:hover { background: var(--color-bg); }

/* ── Projected values in reports ────────────────────────────── */
.projected {
    font-style: italic;
    background: #fef9c3 !important;
    color: #854d0e;
}

.projected-row td {
    font-style: italic;
}

.projected-row:nth-child(even) {
    background: #fefce8;
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="date"], select, textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--color-surface);
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 0.25rem;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-warning { background: var(--color-warning); color: #fff; }
.btn-warning:hover { opacity: 0.9; }

.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-muted   { background: #f3f4f6; color: #6b7280; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Form Rendering (Word template overlay) ────────────────── */
.form-page-container {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    margin: 0 auto 1rem;
}

.form-page {
    position: relative;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    margin-bottom: 1rem;
}

.form-page img {
    width: 100%;
    display: block;
}

.overlay-field {
    position: absolute;
    z-index: 10;
}

.overlay-field input[type="text"],
.overlay-field input[type="number"] {
    border: 1px solid transparent;
    background: rgba(255, 255, 0, 0.15);
    border-radius: 2px;
    padding: 1px 2px;
    font-size: 0.8rem;
}

.overlay-field input[type="text"]:focus,
.overlay-field input[type="number"]:focus {
    background: rgba(255, 255, 0, 0.3);
    border-color: var(--color-primary);
}

.overlay-field input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

/* ── KPI Fragment ───────────────────────────────────────────── */
.kpi-result {
    background: #eff6ff;
    border: 1px solid #93c5fd;
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
}

.kpi-result .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.kpi-result .kpi-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.kpi-result.error {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--color-danger);
}

.kpi-components {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.kpi-component {
    background: var(--color-surface);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.kpi-component .label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.kpi-component .value {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ── Save status ────────────────────────────────────────────── */
.save-status {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    padding: 0.25rem 0.5rem;
}

.save-status.saved {
    color: var(--color-success);
}

/* ── Incomplete report banner ───────────────────────────────── */
.incomplete-banner {
    background: #fef3c7;
    border: 2px solid #f59e0b;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.incomplete-banner .icon {
    font-size: 1.5rem;
}

.incomplete-banner .content {
    flex: 1;
}

.incomplete-banner .title {
    font-weight: 700;
    color: #92400e;
    font-size: 0.95rem;
}

.incomplete-banner .detail {
    font-size: 0.85rem;
    color: #78350f;
}

/* ── Monthly/quarterly status rows ──────────────────────────── */
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.status-row:last-child { border-bottom: none; }

.status-row .label { font-weight: 500; }
.status-row .value { font-size: 1.1rem; font-weight: 600; }
.status-row .status-badge { font-size: 0.75rem; }

/* ── Staleness banner ───────────────────────────────────────── */
.stale-banner {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.stale-banner .title {
    font-weight: 600;
    color: #92400e;
}

.stale-banner .detail {
    font-size: 0.85rem;
    color: #78350f;
    margin-top: 0.25rem;
}

/* ── Audit trail ─────────────────────────────────────────────── */
.audit-event {
    padding: 0.5rem 0.75rem;
    border-left: 3px solid var(--color-border);
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.audit-event .timestamp {
    color: var(--color-text-muted);
    font-size: 0.7rem;
}

.audit-event .actor {
    font-weight: 500;
}

.audit-event .notes {
    color: var(--color-text);
}

/* ── Login page ─────────────────────────────────────────────── */
.login-container {
    max-width: 380px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.login-container h1 {
    font-size: 1.25rem;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--color-primary);
}

.login-container .form-group {
    margin-bottom: 1rem;
}

.login-container .btn {
    width: 100%;
    padding: 0.6rem;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.sub-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1rem;
}

.sub-tabs a {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.sub-tabs a:hover { color: var(--color-text); }
.sub-tabs a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ── Reports layout with vertical bookmark tabs ──────────────── */
.reports-layout {
    display: flex;
    gap: 1rem;
    min-height: 60vh;
}

.reports-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.reports-sidebar .sidebar-heading {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    background: #f9fafb;
    border-bottom: 1px solid var(--color-border);
}

.reports-sidebar .vertical-tabs {
    list-style: none;
    max-height: 70vh;
    overflow-y: auto;
}

.reports-sidebar .vertical-tabs li a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    text-decoration: none;
    color: var(--color-text);
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: all 0.12s;
}

.reports-sidebar .vertical-tabs li a:hover { background: var(--color-bg); }
.reports-sidebar .vertical-tabs li a.active {
    background: #eff6ff;
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 500;
}

.reports-sidebar .vertical-tabs .meta {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.reports-main {
    flex: 1;
    min-width: 0;
}

/* ── PDF preview in report detail ───────────────────────────── */
.pdf-preview {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    overflow: hidden;
}

.pdf-preview iframe {
    width: 100%;
    height: 75vh;
    border: none;
    display: block;
}

.pdf-preview .pdf-fallback {
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
}

/* ── Utility ────────────────────────────────────────────────── */
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-bold { font-weight: 700; }
.font-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.w-full { width: 100%; }
.inline { display: inline; }
.no-bullets { list-style: none; }

/* ── TOML editor ────────────────────────────────────────────── */
.toml-editor {
    width: 100%;
    min-height: 400px;
    font-family: "Courier New", monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fafafa;
}

/* ── Progress bar ───────────────────────────────────────────── */
.progress-bar-container {
    background: var(--color-border);
    border-radius: var(--radius);
    height: 20px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar-fill {
    background: var(--color-success);
    height: 100%;
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #fff;
    font-weight: 600;
}

/* ── Chart images ───────────────────────────────────────────── */
.chart-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    text-align: center;
}

.chart-container img {
    max-width: 100%;
    height: auto;
}

.chart-container .chart-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
}
