/* =============================================
   Control IKEA — Design System
   Premium light-mode with blue/indigo accents
   ============================================= */

/* --- CSS Variables --- */
:root {
    /* Colors */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-input: #f1f5f9;
    --bg-glass: rgba(255, 255, 255, 0.85);

    --border-color: #e2e8f0;
    --border-light: #cbd5e1;

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-white: #ffffff;
    --text-dark: #0f172a;

    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-subtle: rgba(14, 165, 233, 0.1);
    --accent-glow: rgba(14, 165, 233, 0.2);

    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-subtle: rgba(239, 68, 68, 0.1);

    --warning: #f59e0b;
    --warning-subtle: rgba(245, 158, 11, 0.1);

    --success: #10b981;
    --success-subtle: rgba(16, 185, 129, 0.1);

    --info: #6366f1;
    --info-subtle: rgba(99, 102, 241, 0.1);

    /* Gradient */
    --gradient-accent: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    --gradient-card: linear-gradient(135deg, rgba(14, 165, 233, 0.02) 0%, rgba(99, 102, 241, 0.02) 100%);
    --gradient-hero: linear-gradient(135deg, #f0f9ff 0%, #ffffff 50%, #f5f3ff 100%);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 15px rgba(14, 165, 233, 0.15);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Transition */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    min-height: 100vh;
}

/* --- Typography --- */
h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

h4 {
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--accent-hover);
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.page-content {
    padding: var(--space-xl) 0 var(--space-2xl);
}

/* --- Navbar --- */
.navbar {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-md) 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.navbar-brand .brand-icon {
    width: 32px;
    height: 32px;
    background: var(--gradient-accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

/* --- KPI Cards --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-accent);
    opacity: 0;
    transition: var(--transition);
}

.kpi-card:hover::before {
    opacity: 1;
}

.kpi-card .kpi-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.kpi-card .kpi-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-dark);
    letter-spacing: -0.02em;
}

.kpi-card .kpi-value.positive {
    color: var(--success);
}

.kpi-card .kpi-value.negative {
    color: var(--danger);
}

.kpi-card .kpi-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-accent);
    color: var(--text-white);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.btn-danger {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid transparent;
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* --- Forms --- */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239197b3' viewBox='0 0 16 16'%3E%3Cpath d='M8 11.5l-5-5h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-md);
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

.td-actions {
    display: flex;
    gap: var(--space-xs);
    justify-content: flex-end;
}

/* --- Inline Table Input --- */
.inline-input-row {
    background: var(--bg-secondary) !important;
}

.inline-input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: 8px 12px;
    font-size: 0.88rem;
    font-family: inherit;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.inline-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 0 0 2px var(--accent-subtle);
}

.inline-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

tfoot td {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 2px solid var(--border-color);
    font-size: 0.88rem;
}

.td-number {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-open {
    background: var(--success-subtle);
    color: var(--success);
}

.badge-closed {
    background: var(--danger-subtle);
    color: var(--danger);
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: var(--space-xs);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-xl);
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* --- Month Grid --- */
.month-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-md);
}

.month-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.month-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-accent);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.month-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.month-card:hover::after {
    transform: scaleX(1);
}

.month-card .month-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: var(--space-xs);
}

.month-card .month-year {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.month-card .month-badge {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
}

/* --- Login --- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-hero);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card .login-icon {
    width: 56px;
    height: 56px;
    background: var(--gradient-accent);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto var(--space-lg);
}

.login-card h1 {
    margin-bottom: var(--space-xs);
}

.login-card .login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-xl);
}

.login-card .form-input {
    text-align: center;
    font-size: 1rem;
    padding: 14px;
}

.login-card .btn {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 0.95rem;
    margin-top: var(--space-md);
}

.login-error {
    background: var(--danger-subtle);
    color: var(--danger);
    padding: 10px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-top: var(--space-md);
    animation: shake 0.4s ease;
}

/* --- Toast --- */
#toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-sm);
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    min-width: 250px;
    animation: slideInRight 0.3s ease;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toast-success {
    border-left: 3px solid var(--success);
}

.toast-error {
    border-left: 3px solid var(--danger);
}

.toast-info {
    border-left: 3px solid var(--info);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.25s ease;
}

.modal h2 {
    margin-bottom: var(--space-lg);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* --- Inline Add Row --- */
.inline-add {
    display: grid;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border: 1px solid var(--border-color);
    border-top: none;
}

.inline-add .form-input,
.inline-add .form-select {
    padding: 8px 12px;
    font-size: 0.85rem;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.95rem;
    margin-bottom: var(--space-lg);
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.page-header h1 {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.page-header .header-actions {
    display: flex;
    gap: var(--space-sm);
}

/* --- Back Link --- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: var(--space-md);
    cursor: pointer;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--accent);
}

/* --- Category List --- */
.category-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.category-item:hover {
    border-color: var(--border-light);
}

.category-item .cat-name {
    font-weight: 500;
}

.category-item .cat-inactive {
    opacity: 0.4;
    text-decoration: line-through;
}

/* --- Dashboard Print --- */
.dashboard-section {
    margin-bottom: var(--space-xl);
}

.expense-bar-wrapper {
    margin-top: var(--space-sm);
}

.expense-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--bg-input);
    overflow: hidden;
    margin-top: 4px;
}

.expense-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--accent);
    transition: width 0.5s ease;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    50% {
        transform: translateX(8px);
    }

    75% {
        transform: translateX(-4px);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.35s ease both;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .container {
        padding: 0 var(--space-md);
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .month-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tabs {
        overflow-x: auto;
    }
}

/* =============================================
   Print Styles — Clean A4 dashboard
   ============================================= */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: #fff !important;
        color: #1a1a1a !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
    }

    .navbar,
    .tabs,
    .btn,
    .tab-btn,
    .back-link,
    .inline-add,
    #toast-container,
    .modal-overlay,
    .no-print {
        display: none !important;
    }

    .card,
    .kpi-card,
    .table-wrapper {
        background: #fff !important;
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        break-inside: avoid;
    }

    .kpi-card .kpi-label {
        color: #666 !important;
    }

    .kpi-card .kpi-value {
        color: #1a1a1a !important;
    }

    .kpi-card .kpi-value.positive {
        color: #0a8f6a !important;
    }

    .kpi-card .kpi-value.negative {
        color: #c0392b !important;
    }

    thead th {
        background: #f5f5f5 !important;
        color: #333 !important;
    }

    tbody td {
        color: #1a1a1a !important;
    }

    tbody tr:hover {
        background: none !important;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .container {
        max-width: 100% !important;
        padding: 0 !important;
    }

    .page-content {
        padding: 0 !important;
    }

    .print-header {
        display: flex !important;
        justify-content: space-between;
        align-items: flex-start;
        border-bottom: 2px solid #333;
        padding-bottom: 12px;
        margin-bottom: 20px;
    }

    .print-header h1 {
        font-size: 16pt !important;
        color: #1a1a1a !important;
    }

    .print-header .print-meta {
        font-size: 9pt;
        color: #666;
        text-align: right;
    }

    .expense-bar {
        background: #eee !important;
    }

    .expense-bar-fill {
        background: #0a8f6a !important;
    }

    @page {
        margin: 15mm;
        size: A4 portrait;
    }
}