:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #475569;
    --success: #10b981;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --header-bg: #334155;
    
    /* Spreadsheet specific */
    --col-bil-w: 50px;
    --col-nama-w: 250px;
    --col-kat-w: 80px;
    --col-bip-w: 45px;
    
    /* Sticky Offsets Base */
    --sticky-bil: 0;
    --sticky-nama: 50px;
    --sticky-kat-base: 300px; /* 50 + 250 */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Main window doesn't scroll, only the table */
}

/* Dynamic Animated Background */
.app-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background-image: 
        radial-gradient(at 0% 0%, hsla(210, 100%, 90%, 0.8) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(160, 100%, 90%, 0.8) 0, transparent 50%), 
        radial-gradient(at 50% 100%, hsla(220, 100%, 90%, 0.8) 0, transparent 50%);
    background-attachment: fixed;
}

.app-container-fluid {
    width: 100%;
    padding: 1rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    width: 100%;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 8px;
    color: white;
    font-size: 1.5rem;
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.logo-area p {
    font-size: 0.75rem;
    color: #94a3b8;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-radius: 20px;
    font-size: 0.8rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px #10b981;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Main Content & Spreadsheet Layout */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex child scrolling */
}

.spreadsheet-section {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.action-bar-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(248, 250, 252, 0.9);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.left-actions, .right-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.house-selector-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--secondary);
    padding-right: 1rem;
    border-right: 1px solid var(--border);
}

.header-select {
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: bold;
}

.save-indicator {
    font-size: 0.85rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.3s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.save-indicator.show {
    opacity: 1;
    color: var(--success);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-outline {
    background: white;
    color: var(--text-main);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    background: var(--background);
}

/* Spreadsheet Table Container */
.table-container {
    flex-grow: 1;
    overflow: auto;
    position: relative;
    background: white;
}

/* Custom Scrollbar for Table Container */
.table-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.table-container::-webkit-scrollbar-track {
    background: #f1f1f1; 
}
.table-container::-webkit-scrollbar-thumb {
    background: #c1c1c1; 
    border-radius: 5px;
}
.table-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8; 
}

/* Table Architecture */
.spreadsheet-table {
    border-collapse: collapse;
    width: 100%;
    min-width: max-content;
    font-size: 0.85rem;
}

/* Table Headers */
.spreadsheet-table th, .spreadsheet-table td {
    padding: 8px 6px;
    border: 1px solid #cbd5e1;
}

.spreadsheet-table th.col-event {
    padding: 6px 12px !important; /* Rileks sikit: ada ruang kiri-kanan dan sikit atas-bawah */
    vertical-align: middle;
}

.spreadsheet-table th.col-event span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    display: inline-block;
    text-align: center;
    line-height: 1.2;
    letter-spacing: 0.5px;
    white-space: pre-wrap;
}

.spreadsheet-table th {
    text-align: center;
    font-weight: 700;
    font-size: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 10;
    color: white;
    text-transform: uppercase;
}

/* Header Group Colors matching screenshot */
.spreadsheet-table th { background-color: var(--header-bg); }
.group-balapan {
    background: #2563eb !important; /* Blue */
    color: #ffffff !important; 
}
.group-padang { 
    background: #10b981 !important; /* Green */
    color: #ffffff !important; 
}
.highlight-yellow { 
    background: #ffe000 !important; 
    color: #ff0000 !important; 
}

/* Table Cells */
.spreadsheet-table td {
    border: 1px solid var(--border);
    padding: 0; /* Input fills the cell */
    position: relative;
    height: 30px;
}

/* Sticky Columns Logic */
.sticky-col {
    position: sticky !important;
    z-index: 20;
    background: #f8fafc;
}
.spreadsheet-table th.sticky-col {
    z-index: 30; /* Header stays above sticky cells */
    background: var(--header-bg) !important;
}

.col-bil { left: var(--sticky-bil); min-width: var(--col-bil-w); max-width: var(--col-bil-w); text-align: center; font-weight: bold; background: #e2e8f0 !important; }
.col-nama { left: var(--sticky-nama); min-width: var(--col-nama-w); }
.col-kat { left: calc(var(--sticky-kat-base)); min-width: var(--col-kat-w); max-width: var(--col-kat-w); }
.col-bip { left: calc(var(--sticky-kat-base) + var(--col-kat-w)); min-width: var(--col-bip-w); max-width: var(--col-bip-w); }
.col-event { min-width: 45px; text-align: center; }
.col-action { min-width: 45px; text-align: center; }


/* Add shadows to the last sticky column (BIP) */
.col-bip {
    border-right: 2px solid #94a3b8 !important;
}
.spreadsheet-table th.col-bip {
    border-right: 2px solid #1e293b !important;
}

.spreadsheet-container:not(:hover) .col-bip::after {
    box-shadow: none;
}
.col-bip::after {
    content: '';
    position: absolute;
    top: 0;
    right: -5px;
    width: 5px;
    height: 100%;
    box-shadow: inset 5px 0 5px -5px rgba(0,0,0,0.4);
    pointer-events: none;
}

/* Inputs and Selects inside table */
.spreadsheet-table input[type="text"],
.spreadsheet-table select {
    width: 100%;
    height: 100%;
    border: none;
    padding: 0 0.5rem;
    font-size: 0.85rem;
    background: transparent;
    outline: none;
}
.col-bip input {
    text-align: center;
}
.spreadsheet-table input[type="text"]:focus,
.spreadsheet-table select:focus {
    background: #eff6ff;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.spreadsheet-table input.input-error,
.spreadsheet-table select.input-error {
    background: #fee2e2;
    color: #b91c1c;
    box-shadow: inset 0 0 0 1px #ef4444;
}

.spreadsheet-table select {
    appearance: none;
    cursor: pointer;
    text-align: center;
    padding: 0;
}

/* The Ralat Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 2px 4px;
    border-radius: 4px;
    min-width: 20px;
    color: white;
}
.status-ok { background: #10b981; }
.status-err { background: #ef4444; }
.ralat-container {
    display: flex;
    justify-content: center;
    gap: 2px;
    padding: 0 2px;
}

/* Checkboxes */
.cell-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* Tickbox error highlight */
.error-tick-label {
    background-color: #fca5a5 !important;
    border-radius: 4px;
    box-shadow: inset 0 0 0 2px #ef4444;
}
.cell-checkbox input[type="checkbox"].error-tick {
    accent-color: #ef4444 !important; /* Override standard accent */
    outline: 1px solid #ef4444;
}
.cell-checkbox input {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}
.cell-checkbox.checkbox-padang input {
    accent-color: #10b981; /* Green tick for Padang */
}
.cell-checkbox:hover {
    background: #f1f5f9;
}

/* Row states */
.row-active {
    background: #ffffff;
}
.row-active:hover td:not(.sticky-col) {
    background: #f8fafc;
}
.row-empty input {
    color: #94a3b8;
}
.row-empty .col-kat > * {
    display: none;
}
.row-empty .col-event .cell-checkbox {
    display: none;
}

/* Actions: Hover Delete over BIL */
.col-bil .bil-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.col-bil .btn-del-row {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in, visibility 0.2s ease-in;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    z-index: 10;
}
.col-bil:hover .btn-del-row {
    opacity: 1;
    visibility: visible;
}
.col-bil:hover .bil-text {
    opacity: 0;
    transition: opacity 0.2s ease-in;
}
.col-bil .bil-text {
    transition: opacity 0.2s;
}
.btn-del-row:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: -100%;
    background: #ffffff;
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--success);
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}
.toast.show { right: 2rem; }
.toast-icon { font-size: 1.5rem; color: var(--success); }
.toast-message { font-weight: 600; font-size: 0.95rem; }
