/* ============================================
   PEMBUKUAN - Financial Control System
   Premium Light Theme
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---- Design Tokens ---- */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-input: #f8f9fb;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --border-focus: rgba(99, 102, 241, 0.45);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-light: #eef2ff;
    --accent-glow: rgba(99, 102, 241, 0.18);
    --income: #059669;
    --income-bg: rgba(5, 150, 105, 0.08);
    --income-border: rgba(5, 150, 105, 0.2);
    --expense: #dc2626;
    --expense-bg: rgba(220, 38, 38, 0.07);
    --expense-border: rgba(220, 38, 38, 0.18);
    --warning: #d97706;
    --info: #2563eb;
    --info-bg: rgba(37, 99, 235, 0.07);
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.08);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- Container ---- */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 3rem;
    position: relative;
}

/* ---- Icons ---- */
.lucide {
    width: 1.15em;
    height: 1.15em;
    stroke-width: 2;
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: text-bottom;
}

/* ---- Header ---- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-title .icon {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: white;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.header h1 {
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.header p {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 1px;
}

/* ---- Date Info (header) ---- */
.header-date {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1.1rem;
    box-shadow: var(--shadow-sm);
}

.header-date .date-icon {
    width: 38px;
    height: 38px;
    background: var(--accent-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.header-date .date-text {
    display: flex;
    flex-direction: column;
    line-height: 1.35;
}

.header-date .date-day {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-date .date-full {
    font-size: 0.76rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card.income::before { background: linear-gradient(90deg, #059669, #10b981); }
.stat-card.expense::before { background: linear-gradient(90deg, #dc2626, #ef4444); }
.stat-card.balance::before { background: linear-gradient(90deg, var(--accent), #8b5cf6); }
.stat-card.count::before { background: linear-gradient(90deg, var(--info), #3b82f6); }

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-card .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-card.income .value { color: var(--income); }
.stat-card.expense .value { color: var(--expense); }
.stat-card.balance .value { color: var(--accent); }
.stat-card.count .value { color: var(--info); }

/* ---- Card ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

/* ---- Filter Bar ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.filter-group label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
    box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
    filter: brightness(1.05);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #eef0f4;
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--expense-bg);
    color: var(--expense);
    border: 1px solid var(--expense-border);
}

.btn-danger:hover { background: rgba(220, 38, 38, 0.14); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.78rem; }

.btn-icon {
    width: 32px; height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
}

/* ---- Form Elements ---- */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: #fff;
}

.form-control::placeholder { color: var(--text-muted); }

/* ---- Input with Icon ---- */
.input-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon-wrapper .lucide {
    position: absolute;
    left: 0.9rem;
    color: var(--text-muted);
    pointer-events: none;
    width: 1rem;
    height: 1rem;
}

.input-icon-wrapper .form-control {
    padding-left: 2.5rem;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.2rem;
}

select.form-control option {
    background: white;
    color: var(--text-primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ---- Dynamic Fields ---- */
.dynamic-field {
    display: none;
    animation: slideDown 0.3s ease;
}

.dynamic-field.active { display: block; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Table ---- */
.table-wrapper {
    overflow-x: auto;
    margin: 0 -0.5rem;
    padding: 0 0.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

thead th:first-child { border-radius: 8px 0 0 0; }
thead th:last-child { border-radius: 0 8px 0 0; }

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

tbody tr { transition: var(--transition); }
tbody tr:hover { background: #f8fafc; }

.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-income {
    background: var(--income-bg);
    color: var(--income);
    border: 1px solid var(--income-border);
}

.badge-expense {
    background: var(--expense-bg);
    color: var(--expense);
    border: 1px solid var(--expense-border);
}

.badge-period {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(37, 99, 235, 0.18);
    font-size: 0.68rem;
}

/* ---- Amount ---- */
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.income { color: var(--income); }
.amount.expense { color: var(--expense); }

/* ---- Actions ---- */
.actions { display: flex; gap: 0.4rem; }

/* ---- Modal ---- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px; height: 32px;
    border: none;
    background: var(--bg-input);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background: #e2e8f0;
    color: var(--text-primary);
}

.modal-body { padding: 1.5rem; }

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* ---- Section Divider ---- */
.form-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 250px;
}

.toast.success { border-left: 3px solid var(--income); }
.toast.error { border-left: 3px solid var(--expense); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---- Spinner ---- */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Navigation ---- */
.nav-bar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.nav-link:hover { color: var(--accent); }

.nav-link.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ---- Dashboard Specific ---- */
.chart-container {
    position: relative;
    height: 350px;
    width: 100%;
    margin-top: 1rem;
}

.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.insight-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.insight-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.insight-rank {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.insight-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.insight-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.9rem;
}

.insight-name { font-weight: 600; color: var(--text-primary); }
.insight-amount { font-weight: 700; font-variant-numeric: tabular-nums; }

.insight-bar-bg {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.insight-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease-out;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    html { font-size: 14px; }
    .container { padding: 1rem; }
    .header { flex-direction: column; align-items: flex-start; }
    .header-actions { width: 100%; display: flex; justify-content: space-between; align-items: center; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; }
    .filter-group { width: 100%; }
    .filter-group .form-control { width: 100%; }
    .modal { max-height: 95vh; margin: 0.5rem; }
    table { font-size: 0.8rem; }
    thead th, tbody td { padding: 0.6rem 0.6rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 1rem; }
    .stat-card .value { font-size: 1.3rem; }
    .header-date { flex-direction: row; padding: 0.5rem 0.8rem; }
}

/* ---- Flatpickr Custom Theme ---- */
.flatpickr-calendar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-family: 'Inter', sans-serif;
    padding: 2px;
}

.flatpickr-day.selected, 
.flatpickr-day.startRange, 
.flatpickr-day.endRange, 
.flatpickr-day.selected.prevMonthDay, 
.flatpickr-day.selected.nextMonthDay, 
.flatpickr-day.startRange.prevMonthDay, 
.flatpickr-day.startRange.nextMonthDay, 
.flatpickr-day.endRange.prevMonthDay, 
.flatpickr-day.endRange.nextMonthDay {
    background: var(--accent);
    border-color: var(--accent);
}

.flatpickr-day.selected:hover, 
.flatpickr-day.startRange:hover, 
.flatpickr-day.endRange:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.flatpickr-day.today {
    border-color: var(--accent);
}

.flatpickr-day.today:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.flatpickr-months .flatpickr-month {
    color: var(--text-primary);
    fill: var(--text-primary);
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
    font-weight: 700;
}

.flatpickr-weekday {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
}

.flatpickr-calendar.hasTime .flatpickr-time {
    border-top: 1px solid var(--border);
}

.flatpickr-time input:hover, 
.flatpickr-time .flatpickr-am-pm:hover, 
.flatpickr-time input:focus, 
.flatpickr-time .flatpickr-am-pm:focus {
    background: var(--bg-input);
}
