:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --border: #d0d7de;
    --border-dark: #8c959f;
    --header-bg: #217346;
    --header-text: #ffffff;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --danger: #d93025;
    --danger-hover: #b3261e;
    --warning: #f9ab00;
    --text: #1f2328;
    --text-muted: #656d76;
    --row-hover: #f6f8fa;
    --row-selected: #e8f0fe;
    --cell-focus: #1a73e8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.app-header {
    background: linear-gradient(135deg, #1b5e20 0%, #217346 50%, #2e7d32 100%);
    color: white;
    padding: 16px 24px;
    box-shadow: var(--shadow);
}

.app-header-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    max-width: 100%;
}

.app-credit {
    font-size: 0.8rem;
    opacity: 0.88;
    white-space: nowrap;
    margin: 0;
    padding-bottom: 2px;
}

.app-header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    text-align: right;
}

.app-user {
    font-size: 0.85rem;
    margin: 0;
    opacity: 0.95;
}

.app-logout {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.35);
}

.app-logout:hover {
    color: #fff;
    border-bottom-color: #fff;
}

.app-footer {
    text-align: center;
    padding: 16px 24px 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.app-footer strong {
    color: var(--text);
    font-weight: 600;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.app-header p {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 4px;
}

.container {
    max-width: 100%;
    padding: 16px 24px 32px;
}

/* Main navigation — dropdown groups */
.main-nav {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: 16px;
    background: #3d4f5f;
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 0 4px;
    overflow: visible;
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.nav-dropdown-toggle:hover,
.nav-dropdown.open .nav-dropdown-toggle {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.nav-caret {
    font-size: 0.7rem;
    opacity: 0.85;
    transition: transform 0.15s;
}

.nav-dropdown.open .nav-caret {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: #2c3e50;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 100;
    padding: 4px 0;
}

.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-size: 0.875rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    transition: background 0.12s;
    white-space: nowrap;
}

.nav-dropdown-item:first-child {
    border-top: none;
}

.nav-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-dropdown-item.active {
    background: rgba(33, 115, 70, 0.85);
    color: #fff;
    font-weight: 600;
}

.nav-dropdown-item:visited {
    color: rgba(255, 255, 255, 0.92);
}

.nav-dropdown-item.active:visited {
    color: #fff;
}

.nav-item-icon {
    flex-shrink: 0;
    width: 1.25em;
    text-align: center;
}

/* Legacy tab styles (unused) */
.tab-nav {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    background: var(--surface);
    padding: 8px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.tab-btn {
    padding: 10px 18px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

a.tab-btn:visited {
    color: var(--text-muted);
}

a.tab-btn.active:visited {
    color: white;
}

.tab-btn:hover {
    background: var(--row-hover);
    color: var(--text);
}

.tab-btn.active {
    background: var(--header-bg);
    color: white;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.toolbar-group {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

.search-box {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    min-width: 200px;
    color: var(--text);
}

.search-box:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.mapping-unit-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.mapping-unit-filter span {
    white-space: nowrap;
}

.mapping-unit-filter select {
    min-width: 180px;
}

.btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--row-hover);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-success {
    background: var(--header-bg);
    color: white;
    border-color: var(--header-bg);
}

.btn-success:hover {
    background: #1b5e20;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.btn-icon {
    padding: 6px 8px;
}

/* Info bar */
.info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.85rem;
}

.info-bar .hint {
    color: var(--text-muted);
}

/* Spreadsheet */
.sheet-wrapper {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}

.sheet-scroll {
    overflow: auto;
    max-height: calc(100vh - 320px);
    min-height: 400px;
}

.spreadsheet {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-size: 0.8125rem;
}

.spreadsheet-distribusi {
    border-collapse: separate;
    border-spacing: 0;
}

.spreadsheet th,
.spreadsheet td {
    border: 1px solid var(--border);
    padding: 0;
    min-width: 100px;
    max-width: 280px;
    position: relative;
}

.spreadsheet th.col-narrow,
.spreadsheet td.col-narrow {
    min-width: 64px;
    max-width: 88px;
    width: 76px;
    text-align: right;
}

.spreadsheet thead th.col-narrow {
    text-align: center;
    font-size: 0.75rem;
    padding: 8px 4px;
    white-space: normal;
    line-height: 1.2;
}

.spreadsheet td.col-narrow .cell-input {
    text-align: right;
    padding: 6px 6px;
}

.alert-banner {
    margin: 0 0 12px;
    padding: 12px 16px;
    border: 1px solid #f9ab00;
    background: #fef7e0;
    color: #5f4b00;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.alert-banner .btn {
    margin-left: 12px;
    vertical-align: middle;
}

.alert-banner .alert-divider {
    margin: 10px 0;
    border: none;
    border-top: 1px solid #f0d78c;
}

.alert-banner .alert-actions {
    margin-top: 10px;
}

.alert-banner .alert-actions .btn {
    margin: 4px 8px 0 0;
}

.spreadsheet tr.row-unmatched {
    background: #fff8e1;
}

.spreadsheet tr.row-unmatched:hover {
    background: #ffefb8;
}

.spreadsheet tr.row-wait-blok {
    background: #fde8e8;
}

.spreadsheet tr.row-wait-blok:hover {
    background: #f8d4d4;
}

.cell-status-missing {
    color: var(--text);
    font-weight: 600;
}

.spreadsheet thead th {
    background: var(--header-bg);
    color: var(--header-text);
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.spreadsheet .col-row-num {
    min-width: 48px;
    max-width: 48px;
    width: 48px;
    text-align: center;
    background: #e8f5e9;
    color: var(--text);
    font-weight: 600;
    position: sticky;
    left: 0;
    z-index: 5;
}

.spreadsheet thead .col-row-num {
    z-index: 15;
    background: #1b5e20;
    color: white;
}

.spreadsheet .col-actions {
    min-width: 110px;
    max-width: 110px;
    width: 110px;
    text-align: center;
    position: sticky;
    right: 0;
    background: #fafafa;
    z-index: 5;
}

.spreadsheet thead .col-actions {
    z-index: 15;
    background: #1b5e20;
}

.spreadsheet tbody tr:hover {
    background: var(--row-hover);
}

.spreadsheet tbody tr.editing {
    background: var(--row-selected);
}

.spreadsheet tbody tr.new-row {
    background: #fff8e1;
}

.spreadsheet tr.row-ringkasan {
    font-weight: 600;
    background: #f8fafc;
}

.spreadsheet tr.row-ringkasan.row-unmatched {
    background: #fff5f5;
}

/* Distribusi Biaya — warna grup kolom */
.spreadsheet-distribusi thead {
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.spreadsheet-distribusi thead .distribusi-col-sumber {
    background: #2563eb;
    color: #fff;
    text-align: center;
}

.spreadsheet-distribusi thead .distribusi-col-terdistribusi {
    background: #15803d;
    color: #fff;
    text-align: center;
}

.spreadsheet-distribusi thead .distribusi-col-sisa {
    background: #c2410c;
    color: #fff;
    text-align: center;
}

.spreadsheet-distribusi thead .distribusi-col-meta {
    background: #475569;
    color: #fff;
    text-align: center;
}

.spreadsheet-distribusi thead th {
    position: static;
    top: auto;
    vertical-align: middle;
    text-align: center;
}

.spreadsheet-distribusi thead .distribusi-group-row th {
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
    padding: 10px 8px;
}

.spreadsheet-distribusi thead .distribusi-subheader-row th {
    font-size: 0.75rem;
    padding: 8px 6px;
    white-space: normal;
    line-height: 1.25;
}

.spreadsheet-distribusi thead .col-row-num {
    position: sticky;
    left: 0;
    z-index: 33;
}

.spreadsheet-distribusi thead .col-actions {
    position: sticky;
    right: 0;
    z-index: 33;
}

.spreadsheet-distribusi tbody td.distribusi-col-sumber {
    background: #eff6ff;
}

.spreadsheet-distribusi tbody td.distribusi-col-terdistribusi {
    background: #f0fdf4;
}

.spreadsheet-distribusi tbody td.distribusi-col-sisa {
    background: #fff7ed;
    font-weight: 600;
}

.spreadsheet-distribusi tbody tr.row-unmatched td.distribusi-col-sisa {
    background: #ffedd5;
}

.spreadsheet-distribusi tbody tr:hover td.distribusi-col-sumber {
    background: #dbeafe;
}

.spreadsheet-distribusi tbody tr:hover td.distribusi-col-terdistribusi {
    background: #dcfce7;
}

.spreadsheet-distribusi tbody tr:hover td.distribusi-col-sisa {
    background: #fed7aa;
}

.spreadsheet-distribusi tbody td.distribusi-col-sumber .cell-input,
.spreadsheet-distribusi tbody td.distribusi-col-terdistribusi .cell-input,
.spreadsheet-distribusi tbody td.distribusi-col-sisa .cell-input {
    text-align: right;
}

.spreadsheet-distribusi thead .col-row-num,
.spreadsheet-distribusi thead .col-actions {
    background: #334155;
    color: #fff;
}

.spreadsheet tfoot .sheet-total-row {
    background: #f0f6ff;
    border-top: 2px solid var(--border);
}

.spreadsheet tfoot .sheet-total-label {
    font-weight: 600;
    color: var(--text);
    text-align: right;
    padding-right: 8px;
}

.spreadsheet tfoot .cell-total {
    padding: 8px 10px;
    font-weight: 700;
    color: var(--text);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.spreadsheet tbody td {
    color: var(--text);
}

.cell-input {
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    color: var(--text);
    outline: none;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
}

.cell-input:focus {
    background: white;
    box-shadow: inset 0 0 0 2px var(--cell-focus);
    z-index: 1;
    position: relative;
}

.cell-input[readonly] {
    cursor: default;
}

.cell-input.cell-computed {
    background: #f3f8ff;
    color: var(--text);
    font-weight: 500;
    cursor: help;
}

.spreadsheet td .cell-select {
    width: 100%;
    min-width: 220px;
    max-width: 360px;
    font-size: 0.8125rem;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: var(--text);
}

.action-btns {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 4px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #fafafa;
    flex-wrap: wrap;
    gap: 8px;
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.pagination-controls select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text);
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal-wide {
    max-width: 1100px;
}

.distribusi-detail-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text);
}

.distribusi-detail-summary strong {
    display: block;
    color: #656d76;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.distribusi-detail-scroll {
    max-height: 50vh;
    overflow: auto;
}

.distribusi-detail-scroll .spreadsheet {
    min-width: 900px;
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.success { background: #2e7d32; }
.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Loading */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--header-bg);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden { display: none !important; }

/* Paste area */
.paste-area {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text);
    resize: vertical;
}

.paste-area:focus {
    outline: none;
    border-color: var(--accent);
}

.upload-label {
    cursor: pointer;
}

.upload-label input[type="file"] {
    display: none;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #e8f5e9 0%, var(--bg) 45%, #f3f6f8 100%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
    padding: 32px 28px 24px;
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand h1 {
    font-size: 1.75rem;
    color: #1b5e20;
    font-weight: 700;
}

.login-brand p {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.login-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    color: var(--text);
}

.login-input:focus {
    outline: none;
    border-color: var(--header-bg);
    box-shadow: 0 0 0 3px rgba(33, 115, 70, 0.15);
}

.login-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 4px 0 8px;
}

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
}

.login-submit {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    margin-top: 4px;
    justify-content: center;
}

.login-credit {
    margin-top: 24px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .container { padding: 12px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-divider { display: none; }
}
