:root {
    --brand: #a32323;
    --brand-dark: #7f1b1b;
    --brand-soft: #f8eaea;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --line-strong: #d1d5db;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);
    --radius: 10px;
    --sidebar-w: 248px;
    --font: "DM Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.45;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; flex-shrink: 0; }

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 12px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(145deg, var(--brand), var(--brand-dark));
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}
.brand-text strong {
    font-size: 12px;
    letter-spacing: 0.04em;
}
.brand-text span {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

.sidebar-search {
    margin: 8px 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f3f4f6;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--muted);
}
.sidebar-search input {
    border: 0;
    outline: 0;
    background: transparent;
    width: 100%;
}

.sidebar-nav {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #374151;
    border-left: 3px solid transparent;
    transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: #f9fafb; }
.nav-item.active {
    background: var(--brand-soft);
    color: var(--brand);
    border-left-color: var(--brand);
    font-weight: 600;
}

.sidebar-footer {
    border-top: 1px solid var(--line);
    padding: 12px;
}
.sidebar-user-mini {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user-mini strong {
    display: block;
    font-size: 12px;
}
.sidebar-user-mini span {
    font-size: 11px;
    color: var(--muted);
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

/* Main */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 18px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
}
.breadcrumb {
    font-weight: 600;
    color: #111827;
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 12px;
    background: #fafafa;
    color: var(--muted);
}
.topbar-search input {
    border: 0;
    outline: 0;
    background: transparent;
    width: 100%;
}
.topbar-search kbd {
    font-size: 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 6px;
    background: #fff;
    color: #9ca3af;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.entity-chip, .user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 10px;
    background: #fff;
}
.entity-chip span { font-size: 12px; color: #374151; white-space: nowrap; }
.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.user-meta strong { font-size: 12px; }
.user-meta span { font-size: 11px; color: var(--muted); }
.logout-link {
    font-size: 12px;
    color: var(--brand);
    font-weight: 600;
    margin-left: 4px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #4b5563;
}
.mobile-toggle { display: none; }

.content {
    padding: 20px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}
.page-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}
.page-head p {
    margin: 4px 0 0;
    color: var(--muted);
}
.filter-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: -6px 0 16px;
}
.filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.filter-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 12px;
    font-weight: 600;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.filter-pill:hover {
    border-color: #c4c9d2;
    background: #f9fafb;
}
.filter-pill.active {
    background: var(--pill-color, var(--brand));
    border-color: var(--pill-color, var(--brand));
    color: #fff;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    color: #374151;
}
.btn:hover { background: #f9fafb; }
.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn-danger:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; }
.modal-card-sm { width: min(420px, 100%); }
.confirm-text {
    margin: 0 0 6px;
    font-size: 14px;
    color: var(--ink);
}
.confirm-hint {
    margin: 0 0 18px;
    font-size: 12px;
    color: var(--muted);
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.alert {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }

/* Cards / KPI */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}
.kpi-card.accent { border-left: 3px solid var(--brand); }
.kpi-card .label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}
.kpi-card .value {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
}
.card h3 {
    margin: 0 0 12px;
    font-size: 14px;
}
.chart-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
}
.donut {
    width: 92px;
    height: 92px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}
.donut-center {
    position: absolute;
    inset: 18px;
    border-radius: 50%;
    background: #fff;
    display: grid;
    place-items: center;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
}
.legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    flex: 1;
}
.legend li {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 8px;
    align-items: center;
    font-size: 12px;
}
.legend .dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
}
.legend .meta { color: var(--muted); white-space: nowrap; }

.status-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.status-bar {
    height: 6px;
    background: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}
.status-bar > span {
    display: block;
    height: 100%;
    background: var(--brand);
}

/* Forms & table */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.panel-head h2 {
    margin: 0;
    font-size: 15px;
}
.panel-body { padding: 16px; }
.overview-panel { margin-bottom: 16px; }
.overview-kpi { margin-bottom: 12px; }
.overview-charts { margin-bottom: 0; }
.overview-charts .card {
    margin: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group.full { grid-column: 1 / -1; }
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}
.form-group label .req { color: var(--brand); }
.input, .select, .textarea {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 9px 11px;
    background: #fff;
    outline: none;
    width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(163, 35, 35, 0.12);
}
.textarea { min-height: 90px; resize: vertical; }
.input-row {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 8px;
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.toolbar .input, .toolbar .select {
    min-width: 160px;
    max-width: 240px;
}

.table-wrap { overflow: auto; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1100px;
}
.data-table.resizable {
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}
.data-table.resizable th,
.data-table.resizable td {
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-table .cell-truncate {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table .cell-actions {
    overflow: visible;
    white-space: nowrap;
}
.row-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.action-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: #4b5563;
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.action-btn svg { width: 15px; height: 15px; }
.action-btn:hover { background: #f9fafb; }
.action-preview:hover { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.action-edit:hover { color: #b45309; border-color: #fde68a; background: #fffbeb; }
.action-delete:hover { color: var(--brand); border-color: #fecaca; background: #fef2f2; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 80;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-card {
    width: min(640px, 100%);
    max-height: min(86vh, 760px);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: #fff;
}
.modal-head h2 {
    margin: 0;
    font-size: 16px;
}
.modal-body { padding: 16px; }
.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
}
.preview-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.preview-item.full { grid-column: 1 / -1; }
.preview-item .label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.preview-item .value {
    font-size: 14px;
    color: var(--ink);
    word-break: break-word;
}
@media (max-width: 640px) {
    .preview-grid { grid-template-columns: 1fr; }
}
.data-table th {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    background: #fafafa;
    position: relative;
    user-select: none;
}
.data-table .col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}
.data-table .col-resizer::after {
    content: "";
    position: absolute;
    top: 20%;
    bottom: 20%;
    left: 3px;
    width: 2px;
    border-radius: 2px;
    background: transparent;
    transition: background .15s ease;
}
.data-table th:hover .col-resizer::after,
.data-table .col-resizer:hover::after,
body.col-resizing .col-resizer.active::after {
    background: var(--brand);
}
body.col-resizing {
    cursor: col-resize !important;
    user-select: none !important;
}
body.col-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
}
.data-table tbody tr:hover { background: #fcfcfd; }
.data-table .muted { color: var(--muted); font-size: 12px; }
.data-table .cell-stack {
    white-space: normal;
    line-height: 1.25;
}
.data-table .cell-primary {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table .cell-secondary {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table .notes {
    max-width: 220px;
    white-space: normal;
    color: #4b5563;
}
.data-table.resizable .inline-note {
    width: 100%;
    max-width: 100%;
}
.data-table .cell-status {
    text-align: center;
    overflow: visible;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
}
.badge-pt { background: #eff6ff; color: #1d4ed8; }
.badge-cv { background: #f5f3ff; color: #6d28d9; }
.badge-aa { background: #ecfdf5; color: #047857; }
.badge-blb { background: #fff7ed; color: #c2410c; }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-role { background: var(--brand-soft); color: var(--brand-dark); }

.status-icon {
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    cursor: pointer;
    background: transparent;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.status-icon svg { width: 18px; height: 18px; }
.status-icon.sudah {
    color: var(--success);
    background: var(--success-bg);
    border-color: #86efac;
}
.status-icon.belum {
    color: var(--warning);
    background: var(--warning-bg);
    border-color: #fcd34d;
}
.status-icon:not(.is-static):hover {
    transform: scale(1.06);
}
.status-icon.is-static {
    cursor: default;
}
.status-icon:disabled {
    opacity: 0.65;
    cursor: wait;
}
.inline-note {
    width: 160px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 5px 8px;
    background: transparent;
}
.inline-note:hover, .inline-note:focus {
    border-color: var(--line);
    background: #fff;
}

.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--muted);
}

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at top right, rgba(163, 35, 35, 0.12), transparent 35%),
        linear-gradient(180deg, #f8f8f9 0%, #eef0f3 100%);
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 28px;
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}
.login-brand h1 {
    margin: 0;
    font-size: 18px;
}
.login-brand p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}
.login-card .form-group { margin-bottom: 12px; }
.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
    padding: 11px 12px;
}
.login-hint {
    margin-top: 16px;
    padding: 12px;
    border-radius: 10px;
    background: #f9fafb;
    border: 1px dashed var(--line);
    font-size: 12px;
    color: #4b5563;
}
.login-hint code {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}

@media (max-width: 1280px) {
    .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .mobile-toggle { display: grid; }
    .entity-chip { display: none; }
    .user-meta { display: none; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .content { padding: 14px; }
    .page-head { flex-direction: column; }
    .form-grid, .kpi-grid, .card-grid { grid-template-columns: 1fr; }
    .topbar-search { display: none; }
    .input-row { grid-template-columns: 1fr; }
}
