/* ==========================================================================
   Design-system component skins — loaded AFTER styles.css / styles_mobile.css
   so cascade order lets these token-driven rules win over legacy shapes.
   All colors come from tokens.css; dark mode needs no overrides here.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-default,
.form-actions button,
.admin-btn {
    font-family: var(--font-ui);
    font-weight: 600;
    border-radius: var(--radius-btn);
    transition: background-color .12s ease, border-color .12s ease,
                color .12s ease, box-shadow .12s ease;
    cursor: pointer;
}

.btn-primary,
.form-actions button[type="submit"] {
    background: var(--accent);
    color: var(--ink-on-accent);
    border: none;
    box-shadow: 0 2px 6px -1px oklch(0.52 0.14 256 / 0.4);
}

.btn-primary:hover,
.form-actions button[type="submit"]:hover {
    background: var(--accent-hover);
}

.btn-secondary,
.btn-default,
.form-actions button.cancel {
    background: var(--bg-surface);
    color: var(--ink);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover,
.btn-default:hover,
.form-actions button.cancel:hover {
    background: var(--bg-hover);
}

.btn-danger,
.form-actions button.danger,
button.danger {
    background: var(--negative);
    color: var(--ink-on-accent);
    border: none;
}

.btn-danger:hover:not(:disabled),
.form-actions button.danger:hover,
button.danger:hover {
    background: var(--negative-hover);
}

/* Quiet/ghost danger (delete links, revoke buttons) */
.btn-delete,
.delete-btn {
    background: var(--negative-bg);
    color: var(--negative);
    border: 1px solid var(--negative-border);
    border-radius: var(--radius-btn);
}

.btn-delete:hover,
.delete-btn:hover {
    background: var(--negative);
    color: var(--ink-on-accent);
}

/* --------------------------------------------------------------------------
   Inputs
   -------------------------------------------------------------------------- */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
    font-family: var(--font-ui);
    background: var(--bg-surface);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-input);
    transition: border-color .12s ease, box-shadow .12s ease;
}

input[type="number"] {
    font-family: var(--font-mono);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder,
textarea::placeholder {
    color: var(--ink-tertiary);
    opacity: 1;
}

.form-group label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-secondary);
}

/* --------------------------------------------------------------------------
   Modals (legacy .modal used by non-calendar pages; the redesigned calendar
   uses .bc-modal from calendar.css)
   -------------------------------------------------------------------------- */
.modal {
    background: var(--scrim);
}

.modal-content {
    background: var(--bg-raised);
    color: var(--ink);
    border: none;
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-modal);
}

.modal-header h3 {
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.modal .close {
    color: var(--ink-tertiary);
}

.modal .close:hover {
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   Popovers / dropdowns
   -------------------------------------------------------------------------- */
.nav-dropdown,
.menu-panel,
.balance-panel,
.context-menu,
.month-year-picker {
    background: var(--bg-raised);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-menu);
    box-shadow: var(--shadow-popover);
}

/* --------------------------------------------------------------------------
   Tables (admin, reports, import/export)
   -------------------------------------------------------------------------- */
.admin-table th,
.transaction-table th,
.recurring-table th,
.ie-table th {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-secondary);
    background: var(--bg-band);
    border-bottom: 1px solid var(--border);
}

.admin-table td,
.transaction-table td,
.recurring-table td,
.ie-table td {
    border-bottom: 1px solid var(--border);
    color: var(--ink);
}

.admin-table tbody tr:hover,
.transaction-table tbody tr:hover,
.recurring-table tbody tr:hover,
.ie-table tbody tr:hover {
    background: var(--bg-hover);
}

/* Monetary cells read in mono */
td.amount,
td.balance,
.transaction-amount,
.stat-value,
.balance {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Toasts (notifications.js markup)
   -------------------------------------------------------------------------- */
.notification {
    background: var(--bg-raised);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-menu);
    box-shadow: var(--shadow-popover);
    border-left-width: 3px;
}

.notification-error   { border-left-color: var(--negative); }
.notification-success { border-left-color: var(--positive); }
.notification-warning { border-left-color: var(--warning); }
.notification-info    { border-left-color: var(--accent); }

.notification-error .notification-progress   { background: var(--negative); }
.notification-success .notification-progress { background: var(--positive); }
.notification-warning .notification-progress { background: var(--warning); }
.notification-info .notification-progress    { background: var(--accent); }

.notification-close {
    color: var(--ink-tertiary);
}

/* --------------------------------------------------------------------------
   Idle-session modal (session.js markup)
   -------------------------------------------------------------------------- */
.idle-warning-overlay {
    background: var(--scrim);
}

.idle-warning-dialog {
    background: var(--bg-raised);
    color: var(--ink);
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-modal);
}

.idle-warning-countdown,
#idleCountdown {
    font-family: var(--font-mono);
}

.idle-warning-stay {
    background: var(--accent);
    color: var(--ink-on-accent);
    border: none;
    border-radius: var(--radius-btn);
    font-weight: 600;
}

.idle-warning-stay:hover {
    background: var(--accent-hover);
}

.idle-warning-logout {
    background: var(--bg-surface);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-btn);
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Segmented control (design primitive)
   -------------------------------------------------------------------------- */
.segmented {
    display: inline-flex;
    background: var(--bg-inset);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}

.segmented > button,
.segmented > label {
    appearance: none;
    border: none;
    background: transparent;
    padding: 5px 13px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: var(--font-ui);
    color: var(--ink-secondary);
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}

.segmented > button.active,
.segmented > label.active {
    background: var(--bg-surface);
    color: var(--ink);
    box-shadow: 0 1px 3px rgba(20, 30, 60, 0.12);
}

/* --------------------------------------------------------------------------
   Icon picker grid (shared by desktop modal + mobile form sheet — sizing
   constraints here so uploaded SVGs can never render at natural size)
   -------------------------------------------------------------------------- */
.icon-grid-select {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    background: var(--bg-surface);
    max-height: 150px;
    overflow-y: auto;
}

.icon-option {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    min-width: 0;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    color: var(--ink-tertiary);
}

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

.icon-option.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.icon-option img,
.icon-option svg {
    width: 18px;
    height: 18px;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Any transaction icon rendered as an <img> must stay chip-sized */
.bc-icon-chip img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
}

.badge-positive { background: var(--positive-bg); color: var(--positive); }
.badge-negative { background: var(--negative-bg); color: var(--negative); }
.badge-warning  { background: var(--warning-bg);  color: var(--warning); }
.badge-accent   { background: var(--accent-soft); color: var(--accent-text); }

/* --------------------------------------------------------------------------
   Cards / empty states
   -------------------------------------------------------------------------- */
.card,
.admin-card,
.help-section,
.account-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}

.empty-state {
    text-align: center;
    padding: 42px 20px;
    color: var(--ink-tertiary);
    font-size: 14px;
}

.empty-state .empty-state-hint {
    font-size: 12.5px;
    margin-top: 6px;
    color: var(--ink-tertiary);
}

/* --------------------------------------------------------------------------
   Desktop navbar shell (base.html)
   -------------------------------------------------------------------------- */
.navbar {
    height: 60px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-strong);
    box-shadow: none;
    padding: 0 18px;
}

.nav-brand img {
    width: 31px;
    height: 31px;
    border-radius: 8px;
}

.nav-brand-stack {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.nav-brand-name {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.015em;
    color: var(--ink);
}

.nav-brand-sub {
    font-size: 9px;
    color: var(--ink-tertiary);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.navbar .nav-item {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink-secondary);
    border-radius: 8px;
    transition: background-color .12s ease, color .12s ease;
}

.navbar .nav-item:hover {
    background: var(--bg-hover);
    color: var(--ink);
}

.navbar .nav-left > .nav-item.active {
    color: var(--accent-text);
    font-weight: 600;
    position: relative;
}

.navbar .nav-left > .nav-item.active::after {
    content: '';
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: -6px;
    height: 2px;
    border-radius: 1px;
    background: var(--accent);
}

/* Balance chip */
.balance-container .balance {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--positive);
    cursor: pointer;
    transition: background-color .12s ease;
}

.balance-container .balance:hover {
    background: var(--bg-hover);
}

.balance-container .balance.negative {
    color: var(--negative);
}

/* Balance panel stats */
.balance-panel .stat-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-tertiary);
}

.balance-panel .stat-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--ink);
}

.balance-panel .stat-value.stat-success { color: var(--positive); }
.balance-panel .stat-value.stat-danger  { color: var(--negative); }

/* User menu avatar */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 13px;
    font-weight: 700;
}

.user-menu-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--ink-secondary);
}

/* Dropdown rows */
.nav-dropdown .nav-item {
    border-radius: 8px;
    font-size: 13.5px;
}

.user-dropdown-header {
    border-bottom: 1px solid var(--border);
}

.user-dropdown-email {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ink-secondary);
}

/* --------------------------------------------------------------------------
   Mobile shell (base_mobile.html): header + menu bottom sheet.
   Scoped by .mobile-nav (only present in the mobile template) rather than a
   media query -- the server picks templates by user-agent, not viewport.
   -------------------------------------------------------------------------- */
.mobile-nav {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-strong);
    box-shadow: none;
}

.mobile-nav .balance {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--positive);
}

.mobile-nav .menu-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    border-radius: var(--radius-btn);
    padding: 6px 11px;
    color: var(--ink);
}

.mobile-nav .nav-logo {
    width: 26px;
    height: 26px;
    border-radius: 7px;
}

/* Menu panel -> bottom sheet */
.mobile-nav .menu-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto;
    max-height: 78vh;
    overflow-y: auto;
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    border: none;
    box-shadow: 0 -10px 40px -10px rgba(15, 22, 44, 0.3);
    padding: 8px 12px calc(14px + env(safe-area-inset-bottom));
    animation: bcSheetUp var(--dur-sheet) var(--ease-sheet);
    z-index: 1000;
}

.mobile-nav .menu-panel::before {
    content: '';
    display: block;
    width: 38px;
    height: 5px;
    border-radius: 3px;
    background: var(--border-strong);
    margin: 4px auto 10px;
}

.mobile-nav .menu-panel a,
.mobile-nav .menu-panel .menu-button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 13px 14px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    background: transparent;
    border: none;
}

.mobile-nav .menu-panel a:active,
.mobile-nav .menu-panel a:hover {
    background: var(--bg-hover);
}

.mobile-nav .menu-panel .menu-button {
    color: var(--negative);
}

body.menu-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 999;
    animation: bcFade .2s ease;
}

@keyframes bcSheetUp {
    from { transform: translateY(101%); }
    to   { transform: translateY(0); }
}

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

@keyframes bcPop {
    from { opacity: 0; transform: scale(.97) translateY(-3px); }
    to   { opacity: 1; transform: none; }
}
