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

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Roboto', sans-serif;
}

body {
    background-color: #f0f0f0;
    position: relative;
}

/* Custom background icon layer */
.bg-icon-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bg-icon-tile {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
}

.bg-icon-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80px;
    flex-shrink: 0;
}

.bg-icon-col.bg-col-offset {
    margin-top: 40px; /* 50% of 80px row height */
}

.bg-icon-tile i {
    font-size: 28px;
    color: rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
}
.bg-icon-tile i.bg-rot-0 { transform: rotate(0deg); }
.bg-icon-tile i.bg-rot-45 { transform: rotate(45deg); }
.bg-icon-tile i.bg-rot-n45 { transform: rotate(-45deg); }

body.dark-mode .bg-icon-tile i {
    color: rgba(255, 255, 255, 0.08);
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        135deg,
        rgba(245, 245, 245, 0.85) 0%,
        rgba(250, 250, 250, 0.9) 50%,
        rgba(245, 245, 245, 0.85) 100%
    );
    pointer-events: none;
    z-index: -2;
}

.mud-card,
.mud-paper,
.mud-table {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(200, 200, 200, 0.3) !important;
}

/* Dialogs should be opaque, not frosted glass */
.mud-dialog .mud-paper {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background-color: #ffffff !important;
    border: 1px solid rgba(200, 200, 200, 0.5) !important;
}

body.dark-mode .mud-dialog .mud-paper {
    background-color: #2d2d2d !important;
}

body.dark-mode {
    background-color: #1a1a1a;
}

body.dark-mode::after {
    background: linear-gradient(
        135deg,
        rgba(26, 26, 26, 0.85) 0%,
        rgba(20, 20, 20, 0.9) 50%,
        rgba(26, 26, 26, 0.85) 100%
    );
}

#app {
    min-height: 100vh;
}

.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.loading-screen-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    border-left: 3px solid #1976d2;
    padding-left: 1.25rem;
}

.loading-screen h2 {
    color: #3d4f5f;
    font-weight: 300;
    margin: 0;
}

.loading-screen p {
    margin: 0;
}

/* Timeline transaction row hover */
.timeline-txn {
    border-radius: 4px;
    padding: 4px 8px;
    transition: background-color 0.15s;
}

.timeline-txn:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

body.dark-mode .timeline-txn:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

/* Post-save flash: wait 0.5s for the smooth-scroll to complete, then two
   pulses over 1s in the day's own color (falls back to yellow if the row
   didn't set --txn-flash-color). */
.txn-flash {
    --txn-flash-color: #ffd600;
    animation: txn-flash-pulse 0.5s ease-in-out 0.5s 2;
    border: 2px solid transparent;
}

@keyframes txn-flash-pulse {
    0%   { border-color: transparent;          box-shadow: 0 0 0 0 transparent; }
    50%  { border-color: var(--txn-flash-color); box-shadow: 0 0 10px 3px var(--txn-flash-color); }
    100% { border-color: transparent;          box-shadow: 0 0 0 0 transparent; }
}

/* Green flash for the bank import wizard: highlights the row the user
   just categorized so they can spot it in a long list of unmatched
   transactions. Same timing as txn-flash (0.5s delay, 2 pulses over 1s). */
.import-flash {
    animation: import-flash-pulse 0.5s ease-in-out 0.5s 2;
    border: 2px solid transparent !important;
}

@keyframes import-flash-pulse {
    0%   { border-color: transparent; box-shadow: 0 0 0 0 transparent; }
    50%  { border-color: #22c55e;     box-shadow: 0 0 12px 4px rgba(34, 197, 94, 0.7); }
    100% { border-color: transparent; box-shadow: 0 0 0 0 transparent; }
}

/* Tag management row hover */
.tag-row {
    border-radius: 4px;
    transition: background-color 0.15s;
}

.tag-row:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

body.dark-mode .tag-row:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

/* ── Mobile (≤600px) compaction ───────────────────────────────────────── */
@media (max-width: 600px) {
    /* Shrink page titles so the header doesn't eat half the screen */
    .mud-typography-h5 { font-size: 1.15rem !important; line-height: 1.3 !important; }
    .mud-typography-h6 { font-size: 1rem !important; line-height: 1.3 !important; }

    /* Tighten paper/card padding */
    .mud-paper.pa-3 { padding: 8px !important; }
    .mud-card-content { padding: 8px !important; }
    .mud-card-header { padding: 8px !important; }

    /* Dense buttons across the app */
    .mud-button-root {
        padding: 4px 10px !important;
        min-height: 32px !important;
        font-size: 0.8rem !important;
    }
    .mud-button-icon-start { margin-right: 4px !important; }

    /* Let the "Add Transaction" row wrap nicely */
    .page-header-row { flex-wrap: wrap; gap: 8px; }

    /* Timeline: smaller dots, less vertical space, smaller fonts */
    .mud-timeline-item-size-medium .mud-timeline-item-dot {
        width: 24px !important; height: 24px !important;
    }
    .mud-timeline-item { padding-bottom: 4px !important; }
    .timeline-txn { padding: 2px 6px !important; }
    .timeline-txn .mud-typography-body2 { font-size: 0.8rem !important; }
    .timeline-txn .mud-typography-caption { font-size: 0.7rem !important; }

    /* Toggle group + view mode switcher */
    .mud-toggle-group .mud-toggle-item {
        padding: 4px 8px !important;
        min-width: 0 !important;
        font-size: 0.75rem !important;
    }

    /* Date pickers / selects smaller */
    .mud-input-control .mud-input-label { font-size: 0.8rem !important; }
    .mud-input-control input { font-size: 0.85rem !important; }
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: 80px;
    gap: 12px;
    position: relative;
}

.dashboard-grid-item {
    z-index: 2;
    min-width: 0;
    min-height: 0;
    overflow: auto;
}

/* Mobile: stack all widgets full-width, auto height */
@media (max-width: 768px) {
    .dashboard-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    .dashboard-grid-item {
        width: 100% !important;
        min-height: 160px;
        overflow: visible;
    }
    /* Hide grid overlay on mobile — no drag/resize */
    .grid-cell-placeholder {
        display: none;
    }
}

/* Edit mode: grid cell placeholders */
.grid-cell-placeholder {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    z-index: 1;
    transition: background 0.15s;
}
.grid-cell-placeholder.drag-over {
    background: rgba(25, 118, 210, 0.15);
}

/* Drag states */
.dashboard-grid-item.dragging {
    opacity: 0.4;
    z-index: 100;
}

.dashboard-grid-item.edit-mode {
    cursor: default;
    border: 1px dashed transparent;
    border-radius: 8px;
    transition: border-color 0.15s;
}
.dashboard-grid-item.edit-mode:hover {
    border-color: var(--mud-palette-primary);
}

/* Drag handle — left side */
.widget-drag-handle-left {
    position: absolute;
    left: 4px;
    top: 4px;
    z-index: 10;
    cursor: grab;
    opacity: 0.4;
    transition: opacity 0.15s;
    background: rgba(255,255,255,0.9);
    border-radius: 4px;
    padding: 2px;
}
.widget-drag-handle-left:hover {
    opacity: 1;
}
.widget-drag-handle-left:active {
    cursor: grabbing;
}

/* Resize handle */
.widget-resize-handle {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    opacity: 0.3;
    transition: opacity 0.15s;
    z-index: 11;
}
.widget-resize-handle:hover {
    opacity: 0.8;
}

/* Widget container */
.widget-container {
    position: relative;
    height: 100%;
}

.widget-toolbar {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 10;
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,0.9);
    border-radius: 4px;
    padding: 2px;
}

.widget-picker-panel {
    position: fixed;
    top: 64px;
    right: 16px;
    width: 280px;
    z-index: 1100;
    border-radius: 8px;
    background: var(--mud-palette-surface);
}
