/* BudStab - Maybe Finance Inspired Theme (Dark Graphite)
   Optimized for Raspberry Pi Zero 2 W
*/

:root {
    /* Palette - Maybe Finance Dark Graphite */
    --color-bg-base: #111111;
    --color-bg-surface: #1a1a1a;
    --color-bg-subtle: #262626;
    --color-bg-hover: #333333;

    --color-text-primary: #ffffff;
    --color-text-secondary: #a1a1aa;
    /* Zinc-400 */
    --color-text-tertiary: #71717a;
    /* Zinc-500 */

    --color-border: #333333;
    --color-border-subtle: #262626;

    /* Accents - Neon/Pastel styles */
    --color-primary: #ffffff;
    /* Monochrome Primary */
    --color-primary-fg: #000000;

    --color-income: #22c55e;
    /* Green-500 */
    --color-income-soft: rgba(34, 197, 94, 0.15);

    --color-expense: #ef4444;
    /* Red-500 */
    --color-expense-soft: rgba(239, 68, 68, 0.15);

    --color-blue: #3b82f6;
    --color-purple: #a855f7;
    --color-yellow: #eab308;

    /* Material/Design Tokens */
    --md-sys-color-background: var(--color-bg-base);
    --md-sys-color-surface: var(--color-bg-surface);
    --md-sys-color-surface-variant: var(--color-bg-subtle);
    --md-sys-color-on-surface: var(--color-text-primary);
    --md-sys-color-on-surface-variant: var(--color-text-secondary);
    --md-sys-color-outline: var(--color-border);
    --md-sys-color-outline-variant: var(--color-border-subtle);

    --md-sys-color-primary: var(--color-primary);
    --md-sys-color-on-primary: var(--color-primary-fg);
    --md-sys-color-secondary-container: var(--color-bg-hover);
    --md-sys-color-on-secondary-container: var(--color-text-primary);

    --md-sys-color-error: var(--color-expense);

    /* Shapes - Sharper, cleaner (Maybe style) */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Layout */
    --nav-width: 240px;
    --header-height: 64px;
    --bottom-nav-height: 64px;
}

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

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

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--color-text-primary);
}

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 32px;
    padding-bottom: 96px;
    /* Mobile spacing */
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Navigation - Sidebar (Desktop) */
.nav-bar {
    background-color: var(--color-bg-base);
    border-right: 1px solid var(--color-border);
    width: var(--nav-width);
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    gap: 8px;
    z-index: 50;
}

/* Mobile Nav overrides */
@media (max-width: 768px) {
    .nav-bar {
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0;
        right: 0;
        width: 100%;
        height: var(--bottom-nav-height);
        flex-direction: row;
        justify-content: flex-start;
        padding: 0 8px;
        gap: 0;
        border-right: none;
        border-top: 1px solid var(--color-border);
        background: var(--color-bg-base);
        z-index: 1000;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Firefox */
    }

    .nav-bar::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari */
    }

    .nav-item {
        flex: 0 0 auto;
        min-width: 64px;
        scroll-snap-align: start;
    }

    .nav-item-label {
        font-size: 10px !important;
    }

    .main-content {
        padding: 16px;
        padding-bottom: 96px;
    }
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.nav-item:hover {
    background-color: var(--color-bg-surface);
    color: var(--color-text-primary);
}

.nav-item.active {
    background-color: var(--color-bg-subtle);
    color: var(--color-text-primary);
}

.nav-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .nav-item {
        flex-direction: column;
        gap: 4px;
        padding: 8px;
        background: transparent !important;
    }

    .nav-item.active {
        color: var(--color-primary);
    }

    .nav-item-icon span {
        font-size: 24px !important;
    }
}

/* Typography */
h1,
h2,
h3,
h4 {
    color: var(--color-text-primary);
    font-weight: 600;
    letter-spacing: -0.02em;
}

h1 {
    font-size: 28px;
    margin-bottom: 24px;
}

h2 {
    font-size: 20px;
    margin-bottom: 16px;
}

/* Cards - Maybe Style */
.card {
    background-color: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
}

.card-outlined {
    background: transparent;
    border: 1px solid var(--color-border);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    /* Sharper */
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    gap: 8px;
}

.btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-primary-fg);
}

.btn-primary:hover {
    filter: brightness(0.9);
}

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

.btn-secondary:hover {
    background-color: var(--color-bg-hover);
}

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

.btn-danger:hover {
    background-color: rgba(239, 68, 68, 0.25);
}

/* FAB (Fixed) */
.fab {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 20px;
    /* Squircle */
    background-color: var(--color-primary);
    color: var(--color-primary-fg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 150;
    transition: transform 0.2s, opacity 0.2s;
}

/* Hide FAB when multiselect mode is active */
.tx-mobile-view.multiselect-mode~.fab,
body:has(.tx-mobile-action-bar.visible) .fab {
    opacity: 0;
    pointer-events: none;
}

.fab:hover {
    transform: translateY(-2px);
}

.fab-label {
    display: none;
}

/* Icon only default */

@media (min-width: 769px) {
    .fab {
        display: none;
    }

    /* Hide FAB on desktop, use header buttons */
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 32px;
    font-weight: 600;
    color: var(--color-text-primary);
    letter-spacing: -1px;
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: 14px;
}

th {
    background: var(--color-bg-surface);
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: var(--color-bg-subtle);
}

/* Forms */
.form-control {
    width: 100%;
    height: 42px;
    background-color: var(--color-bg-base);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0 16px;
    color: var(--color-text-primary);
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-text-secondary);
}

/* Charts - Constrained */
.chart-container {
    position: relative;
    height: 300px;
    /* Fixed height for dashboard charts */
    width: 100%;
}

.chart-wrapper-small {
    height: 200px;
}

/* Utilities */
.text-income {
    color: var(--color-income);
}

.text-expense {
    color: var(--color-expense);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.badge-secondary {
    background: var(--color-bg-subtle);
    color: var(--color-text-secondary);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg-base);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

/* Account List styling adjustments */
.account-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
}

.account-card-row:last-child {
    border-bottom: none;
}

/* Utilities */
.d-none {
    display: none !important;
}

.d-flex {
    display: flex !important;
}

@media (min-width: 768px) {
    .d-md-flex {
        display: flex !important;
    }

    .d-md-none {
        display: none !important;
    }

    .d-md-block {
        display: block !important;
    }
}

/* Utilities */
.d-none {
    display: none !important;
}

.d-flex {
    display: flex !important;
}

@media (min-width: 768px) {
    .d-md-flex {
        display: flex !important;
    }

    .d-md-none {
        display: none !important;
    }

    .d-md-block {
        display: block !important;
    }
}

/* Restoring Segmented Control */
.segmented-control {
    display: flex;
    background-color: var(--color-bg-base);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}

.segmented-control label {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--color-text-secondary);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-check {
    position: absolute;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
}

.btn-check:checked+label {
    background-color: var(--color-bg-subtle);
    color: var(--color-text-primary);
    font-weight: 500;
    border-color: var(--color-border);
}

.btn-check[value="income"]:checked+label {
    background-color: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.3);
}

.btn-check[value="expense"]:checked+label {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Category Dropdown/List Components */
.category-selector {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-bg-base);
    overflow: hidden;
}

.category-selector-toggle {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background-color: var(--color-bg-base);
    transition: background 0.2s;
}

.category-selector-toggle:hover {
    background-color: var(--color-bg-subtle);
}

.category-selector-menu {
    border-top: 1px solid var(--color-border);
    max-height: 300px;
    overflow-y: auto;
    background-color: var(--color-bg-surface);
    display: none;
}

.category-selector-menu.show {
    display: block;
}

.category-option {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-bg-subtle);
    transition: background 0.1s;
}

.category-option:hover {
    background-color: var(--color-bg-hover);
}

.category-option.selected {
    background-color: var(--color-bg-subtle);
    color: var(--color-primary);
}

.category-option-child {
    padding-left: 48px;
    background-color: rgba(0, 0, 0, 0.2);
}

/* Tags */
.tag-checkbox input:checked+.tag-label {
    background-color: var(--color-primary) !important;
    color: var(--color-primary-fg) !important;
    border-color: var(--color-primary) !important;
}

/* =============================================
   Mobile Transaction Cards
   ============================================= */

/* Hide mobile view on desktop, hide desktop view on mobile */
.tx-desktop-view {
    display: block;
}

.tx-mobile-view {
    display: none;
}

@media (max-width: 768px) {
    .tx-desktop-view {
        display: none !important;
    }

    .tx-mobile-view {
        display: block !important;
    }
}

/* Month header - sticky */
.tx-month-header {
    position: sticky;
    top: 0;
    background: var(--color-bg-base);
    padding: 12px 0;
    margin: 0 -16px;
    padding-left: 16px;
    font-weight: 600;
    font-size: 13px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
}

/* Transaction card */
.tx-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--color-border-subtle);
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tx-card:active {
    background: var(--color-bg-hover);
}

.tx-card.selected {
    background: var(--color-bg-subtle);
}

.tx-card.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--color-primary);
}

/* Category icon container */
.tx-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

/* Main content area */
.tx-card-content {
    flex: 1;
    min-width: 0;
    /* Enable text truncation */
}

.tx-card-title {
    font-weight: 500;
    font-size: 15px;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-card-subtitle {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.tx-card-payee {
    font-size: 12px;
    color: var(--color-text-tertiary);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* Amount and date */
.tx-card-right {
    text-align: right;
    flex-shrink: 0;
}

.tx-card-amount {
    font-weight: 600;
    font-size: 15px;
}

.tx-card-amount.income {
    color: var(--color-income);
}

.tx-card-amount.expense {
    color: var(--color-expense);
}

.tx-card-amount.transfer {
    color: var(--color-text-secondary);
}

.tx-card-date {
    font-size: 12px;
    color: var(--color-text-tertiary);
    margin-top: 2px;
}

/* Selection checkbox (appears in multi-select mode) */
.tx-card-checkbox {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    border: 2px solid var(--color-border);
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.tx-mobile-view.multiselect-mode .tx-card-checkbox {
    display: flex;
}

.tx-card.selected .tx-card-checkbox {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.tx-card.selected .tx-card-checkbox::after {
    content: '✓';
    color: var(--color-primary-fg);
    font-size: 14px;
    font-weight: bold;
}

/* Long press animation */
.tx-card.pressing {
    transform: scale(0.98);
    background: var(--color-bg-hover);
}

/* Multi-select mode bottom bar */
.tx-mobile-action-bar {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 16px);
    left: 16px;
    right: 16px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hide mobile action bar on desktop */
@media (min-width: 769px) {
    .tx-mobile-action-bar {
        display: none !important;
    }
}

.tx-mobile-action-bar.visible {
    transform: translateY(0);
}

.tx-mobile-action-bar-count {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
}

.tx-mobile-action-bar-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.tx-mobile-action-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--color-bg-subtle);
    border: none;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.tx-mobile-action-btn:active {
    background: var(--color-bg-hover);
}

.tx-mobile-action-btn.danger {
    color: var(--color-expense);
}

/* Empty state for mobile */
.tx-empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--color-text-secondary);
}

.tx-empty-state-icon {
    font-size: 48px;
    opacity: 0.5;
    margin-bottom: 16px;
}

/* Mobile filters - collapsible */
.tx-mobile-filters {
    margin-bottom: 16px;
}

.tx-mobile-filters-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.tx-mobile-filters-content {
    display: none;
    padding: 16px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.tx-mobile-filters-content.show {
    display: block;
}

/* Custom Checkbox Styling */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-surface);
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
    flex-shrink: 0;
    vertical-align: middle;
    margin: 0;
}

input[type="checkbox"]:hover {
    border-color: var(--color-primary);
    background: var(--color-surface-light);
}

input[type="checkbox"]:checked {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid var(--color-primary-fg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb, 74, 222, 128), 0.25);
}