/* Layout A: Clean Minimalist Cards - Stacked vertical design */

:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    
    /* Safe-area insets for notches and gesture bars */
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
    
    /* Design tokens */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    
    --font-xs: 10px;
    --font-sm: 12px;
    --font-md: 14px;
    --font-lg: 16px;
    --font-xl: 20px;
    
    --radius-md: 8px;
    --touch-target-min: 44px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.shell {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    padding-top: calc(20px + var(--safe-top));
    padding-bottom: calc(20px + var(--safe-bottom));
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
}

.app-header {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.app-title h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.app-title p {
    color: var(--text-light);
    font-size: 14px;
}

.app {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.card-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.hint {
    font-size: 13px;
    color: var(--text-light);
}

/* Month comparison (ledger-driven, no dropdowns) */
.kpi.kpi-compare {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 16px !important;
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
}

.info-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-light);
    font-size: 12px;
    font-weight: 700;
    margin-left: 6px;
    background: var(--card-bg);
    cursor: default;
}

.compare-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
}

.compare-actions {
    display: none;
}

.btn.small {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
}

.compare-month {
    font-weight: 700;
    color: var(--primary);
    font-size: 12px;
    margin-bottom: 4px;
}

.compare-month-wrapper {
    position: relative;
    margin-bottom: 4px;
}

.compare-month-label {
    font-weight: 700;
    color: var(--primary);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

.compare-month-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.compare-metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.compare-metric-main b {
    font-size: 16px;
    font-weight: 800;
}

.compare-metric span {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
}

.compare-metric b {
    font-size: 13px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.compare-note {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-light);
    border-top: 1px solid var(--border);
    padding-top: 8px;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compare-vs {
    display: none;
}

.compare-summary {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

.compare-diff-abs {
    font-size: 14px;
    font-weight: 900;
}

.compare-diff-pct {
    font-size: 13px;
    font-weight: 900;
    opacity: 0.95;
}

.compare-summary.positive { color: var(--danger); }
.compare-summary.negative { color: var(--success); }


.compare-delta {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  display: block;
  text-align: left;
}

.compare-delta.positive { color: var(--danger); }
.compare-delta.negative { color: var(--success); }

/* Ledger selection */
.ledger-row.compare-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.ledger-row {
    cursor: pointer;
}

.ledger-row .ledger-actions {
    cursor: default;
}

.compare-row {
  display: flex !important;
  flex-direction: row !important;
  gap: 8px;
  align-items: stretch;
  margin-top: 8px;
  flex-wrap: nowrap !important;
  width: 100%;
}

.compare-card.compact,
.compare-most-charged.compact {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start;
  gap: 4px;
  box-shadow: none;
  min-width: 0;
}

.compare-card.compact {
  flex: 1 1 0 !important;
  min-height: 48px;
  padding: 14px 12px !important;
}

.compare-most-charged.compact {
  flex: 0 0 120px !important;
  min-width: 120px;
  max-width: 120px;
  padding: 14px 12px !important;
  cursor: pointer;
  transition: background 0.15s;
}

.compare-most-charged.compact:hover {
  background: var(--bg);
}

.most-charged-month {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

#most-charged-label-span {
  color: var(--text-light);
}

#most-charged-value {
  color: var(--danger);
}

@media (max-width: 900px) {
  .compare-row {
    gap: 6px;
  }
  .compare-card.compact,
  .compare-most-charged.compact {
    padding: 8px;
  }
}

/* Dashboard KPIs */
.kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.kpi {
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.kpi:nth-child(3) {
    grid-column: 1 / -1;
}

@media (min-width: 768px) {
    .kpis {
        grid-template-columns: 1fr 1fr;
    }
}

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

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Form */
.form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-compact {
    gap: 16px;
}

.form-compact .grid {
    gap: 12px;
}

.form-compact .field label {
    font-size: 13px;
    margin-bottom: 4px;
    font-weight: 500;
}

.form-compact .field label .optional {
    font-weight: 400;
    color: var(--text-light);
    font-size: 12px;
}

.form-compact .field input {
    padding: 8px 10px;
    font-size: 14px;
}

.form-compact .btn {
    padding: 10px 18px;
    font-size: 14px;
}

.form-preview {
    display: flex;
    gap: 16px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.form-preview-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.form-preview-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
}

.form-preview-value {
    font-size: 15px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.field input {
    width: 100%;
    padding: 12px;
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    transition: border-color 0.2s;
}

.field input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Preview */
.preview {
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.preview-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.preview-row:not(:last-child) {
    border-bottom: 1px dashed var(--border);
}

.preview-label {
    font-size: 14px;
    color: var(--text-light);
}

.preview-value {
    font-size: 16px;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--border);
    color: var(--text);
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

.btn.danger {
    background: var(--danger);
    color: white;
}

.form-actions {
    display: flex;
    gap: 12px;
}

.form-actions .btn {
    flex: 1;
}

/* Ledger */
.ledger {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ledger-row {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 12px;
}

.ledger-header-row {
    background: transparent;
    border: none;
    padding: 0 12px;
    margin-bottom: 4px;
    cursor: default;
    align-items: flex-end;
}

.ledger-header-row .data-label {
    color: var(--text-light);
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

.ledger-header-row .data-label:hover {
    color: var(--primary);
}

.ledger-header-row .ledger-month {
    color: var(--text-light);
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
    align-self: flex-end;
}

.ledger-header-row .ledger-month:hover {
    color: var(--primary);
}

.ledger-header-cell {
    cursor: pointer !important;
}

.ledger-header {
    display: none;
}

.ledger-month {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    color: var(--primary);
}

.ledger-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.icon-btn:hover {
    transform: scale(1.05);
}

.icon-btn.danger {
    color: var(--danger);
}

.ledger-data {
    display: grid;
    grid-template-columns: repeat(5, minmax(88px, 1fr));
    gap: 8px;
}

.ledger-grid {
    display: none;
}

.ledger-cell {
    display: none;
}

.data-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-end;
}

.data-label {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 500;
    text-align: right;
}

.data-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.data-item.highlight .data-value {
    font-size: 14px;
}

.cell-label {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.cell-value {
    font-size: 16px;
    font-weight: 600;
}

/* Context menu for long press */
.context-menu {
    position: absolute;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
    min-width: 120px;
}

.context-menu-item {
    display: block;
    width: 100%;
    padding: 14px 16px;
    min-height: 44px;
    border: none;
    background: none;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--bg);
}

.context-menu-item.danger {
    color: var(--danger);
}

.context-menu-item + .context-menu-item {
    border-top: 1px solid var(--border);
}

.year-picker {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  padding: 16px 20px 16px 20px;
  z-index: 100;
  min-width: 180px;
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.year-picker.open {
    display: flex;
}
.year-picker[hidden] {
    display: none !important;
}
.month-picker {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.10);
    padding: 16px 20px 16px 20px;
    z-index: 101;
    min-width: 220px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}
.month-picker.open {
    display: flex;
}
.month-picker[hidden] {
    display: none !important;
}
.month-picker-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary);
}
.month-picker-year-list {
    display: flex;
    flex-direction: row;
    gap: 6px;
    margin-bottom: 8px;
}
.month-picker-year-list button {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.month-picker-year-list button.selected,
.month-picker-year-list button:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.month-picker-month-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.month-picker-month-list button {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.month-picker-month-list button.selected,
.month-picker-month-list button:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.month-picker-empty-hint {
    font-size: 13px;
    color: var(--text-light);
}
#month-picker-cancel {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-light);
    background: none;
    border: none;
    cursor: pointer;
    text-align: center;
}
.year-picker-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--primary);
}
.year-picker-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#year-picker.empty .year-picker-list {
    display: none;
}
.year-picker-empty-hint {
    font-size: 13px;
    color: var(--text-light);
}
.year-picker-list button {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-variant-numeric: tabular-nums;
}
.year-picker-list button strong {
    font-size: 14px;
    font-weight: 700;
}
.year-picker-list button span {
    color: var(--text-light);
    font-size: 12px;
    font-weight: 500;
}
.year-picker-list button.selected,
.year-picker-list button:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.year-picker-list button.selected span,
.year-picker-list button:hover span {
    color: #e0e8ff;
}
#year-picker-cancel {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-light);
  background: none;
  border: none;
  cursor: pointer;
  text-align: center;
}
#kpi-avg-charge-block {
  position: relative;
}

/* Stats Icon Button */
.stats-icon-btn {
    position: fixed;
    top: calc(20px + var(--safe-top));
    right: calc(20px + var(--safe-right));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card-bg);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.stats-icon-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.stats-icon-btn:active {
    transform: scale(1.05);
}

.stats-icon-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}

/* Sync Icon Button */
.sync-icon-btn {
    position: fixed;
    top: calc(80px + var(--safe-top));
    right: calc(20px + var(--safe-right));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card-bg);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.sync-icon-btn:hover {
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sync-icon-btn:active {
    transform: scale(1.05) rotate(90deg);
}

.sync-icon-btn.loading {
    animation: sync-spin 1s linear infinite;
    background: var(--primary-light);
    border-color: var(--primary);
    pointer-events: none;
}

@keyframes sync-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.sync-icon-btn.success {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

/* Stats Modal */
.stats-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    padding-top: calc(20px + var(--safe-top));
    padding-bottom: calc(20px + var(--safe-bottom));
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
    overflow-y: auto;
}

.stats-modal[hidden] {
    display: none;
}

.stats-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

.stats-modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    z-index: 2;
    max-width: 600px;
    width: 100%;
    max-height: calc(100vh - 40px - var(--safe-top) - var(--safe-bottom));
    display: flex;
    flex-direction: column;
}

.stats-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid var(--border);
}

.stats-modal-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.stats-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--text-light);
}

.stats-modal-close:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.stats-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* Stats Year Filter */
.stats-year-filter {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.stats-year-filter label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.stats-year-filter select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--card-bg);
    cursor: pointer;
}

.stats-year-filter select:focus {
    outline: none;
    border-color: var(--primary);
}

.stats-filter-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 16px;
}

.stats-clear-filter {
    padding: 4px 8px;
    font-size: 12px;
    background: white;
    color: var(--primary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

/* Stats Sections */
.stats-section {
    margin-bottom: 32px;
}

.stats-section:last-child {
    margin-bottom: 0;
}

.stats-section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-item {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.stats-item-label {
    color: var(--text-light);
    font-size: 13px;
}

.stats-item-value {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stats-item-value.red {
    color: var(--danger);
}

.stats-item-value.green {
    color: var(--success);
}

/* Sync Result Modal Styles */
.sync-result-message {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 15px;
    line-height: 1.6;
}

.sync-result-message.success {
    background: #d1fae5;
    border: 2px solid var(--success);
    color: #065f46;
}

.sync-result-message.error {
    background: #fee2e2;
    border: 2px solid var(--danger);
    color: #991b1b;
}

.sync-result-message.warning {
    background: #fef3c7;
    border: 2px solid #f59e0b;
    color: #92400e;
}

.sync-result-message.info {
    background: #dbeafe;
    border: 2px solid var(--primary);
    color: #1e40af;
}

.sync-result-details {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.sync-result-details:last-child {
    margin-bottom: 0;
}

.sync-detail-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.sync-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.sync-detail-item:last-child {
    border-bottom: none;
}

.sync-detail-item span {
    font-size: 14px;
    color: var(--text-light);
}

.sync-detail-item strong {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.stats-item-highlight {
    font-weight: 700;
    color: var(--primary);
}

@media (max-width: 640px) {
    .ledger-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .ledger-month {
        padding-bottom: 4px;
        border-bottom: 1px solid var(--border);
    }
    
    .ledger-data {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .ledger-actions {
        justify-content: flex-end;
    }
    
    .stats-modal {
        padding: 12px;
        padding-top: calc(12px + var(--safe-top));
        padding-bottom: calc(12px + var(--safe-bottom));
        align-items: flex-start;
    }
    
    .stats-modal-content {
        max-height: calc(100vh - 24px - var(--safe-top) - var(--safe-bottom));
    }
    
    .stats-modal-header {
        padding: 16px;
    }
    
    .stats-modal-body {
        padding: 16px;
    }
    
    .stats-icon-btn {
        top: calc(12px + var(--safe-top));
        right: calc(12px + var(--safe-right));
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    .sync-icon-btn {
        top: calc(68px + var(--safe-top));
        right: calc(12px + var(--safe-right));
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    .stats-year-filter {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stats-year-filter select {
        width: 100%;
    }
    
    .stats-item {
        font-size: 13px;
    }
}


.empty {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.row {
    display: flex;
    gap: 12px;
}

.row .btn {
    flex: 1;
}

/* Loading spinner */
.app-loader {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    gap: 16px;
}

.app-loader[hidden] {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.app-loader p {
    font-size: 14px;
    color: var(--text);
    font-weight: 500;
}

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

/* Mobile Responsive */
@media (max-width: 768px) {
    .shell {
        padding: 12px;
        padding-top: calc(12px + var(--safe-top));
        padding-bottom: calc(20px + var(--safe-bottom));
        padding-left: calc(12px + var(--safe-left));
        padding-right: calc(12px + var(--safe-right));
    }
    
    .app-header {
        padding: 20px;
    }
    
    .card {
        padding: 16px;
    }
    
    .kpis {
        grid-template-columns: 1fr 1fr;
    }
    
    .kpi-value {
        font-size: 22px;
    }
    
    .grid {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    /* Mobile ledger compact layout - single row */
    .ledger-row {
        grid-template-columns: 55px 1fr;
        gap: 6px;
        padding: 8px 10px;
        align-items: center;
    }
    
    .ledger-month {
        font-size: 11px;
        font-weight: 700;
        padding: 0;
        border: none;
        margin: 0;
        min-width: 55px;
        font-variant-numeric: tabular-nums;
    }
    
    .ledger-data {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 3px;
        flex: 1;
    }
    
    .data-item {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        min-width: 0;
    }
    
    .data-item .data-value {
        text-align: right;
        font-size: 11px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-variant-numeric: tabular-nums;
    }
    
    .data-item .data-label {
        font-size: 9px;
    }
    
    .data-item.highlight .data-value {
        font-size: 11px;
        font-weight: 700;
    }
    
    /* Safe-area for pickers */
    .year-picker,
    .month-picker {
        padding-bottom: calc(20px + var(--safe-bottom));
    }
}

/* Sync Progress Modal */
.sync-progress-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.sync-progress-modal[hidden] {
    display: none;
}

.sync-progress-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.sync-progress-content h3 {
    margin: 0 0 20px 0;
    font-size: 18px;
    text-align: center;
    color: var(--text);
}

.sync-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sync-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: var(--bg);
    transition: all 0.3s;
}

.sync-step.completed {
    background: rgba(34, 197, 94, 0.1);
}

.sync-step.completed .sync-step-icon {
    background: var(--success);
    color: white;
}

.sync-step.active {
    background: rgba(37, 99, 235, 0.1);
    border: 2px solid var(--primary);
}

.sync-step.active .sync-step-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

.sync-step.pending {
    opacity: 0.5;
}

.sync-step-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--border);
    font-size: 18px;
    flex-shrink: 0;
}

.sync-step-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.sync-status-message {
    margin-top: 16px;
    padding: 12px;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    color: var(--text-light);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

