/* ===== CSS Variables / Theming ===== */
:root {
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    /* Spacing scale (these were referenced across the app but never defined,
       so paddings/gaps using them silently collapsed — audit 2026-06-03, #43) */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --header-height: 50px;
    --bottom-nav-height: 64px;
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 56px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body.dark-theme {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: #1e1b4b;
    --success-light: #064e3b;
    --warning-light: #78350f;
    --danger-light: #7f1d1d;
    --info-light: #1e3a5f;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
}

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

html { font-size: 14px; -webkit-text-size-adjust: 100%; overflow-x: hidden; overscroll-behavior-y: contain; }
html, body { max-width: 100vw; }

/* ===== Pull-to-Refresh ===== */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 9999;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-card);
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s;
    opacity: 0;
    pointer-events: none;
}
.ptr-indicator.ptr-visible {
    opacity: 1;
}
.ptr-indicator.ptr-refreshing {
    transform: translateX(-50%) translateY(16px);
    opacity: 1;
}
.ptr-arrow {
    width: 20px;
    height: 20px;
    stroke: var(--primary);
    transition: transform 0.2s;
}
.ptr-indicator.ptr-ready .ptr-arrow {
    transform: rotate(180deg);
}
.ptr-indicator.ptr-refreshing .ptr-arrow {
    animation: ptrSpin 0.7s linear infinite;
}
@keyframes ptrSpin { to { transform: rotate(360deg); } }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding-bottom: 16px;
    -webkit-font-smoothing: antialiased;
    transition: padding-left 0.2s ease;
}

body.has-sidebar {
    padding-left: var(--sidebar-width);
}

body.has-sidebar.sidebar-collapsed {
    padding-left: var(--sidebar-collapsed-width);
}

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

img { max-width: 100%; }

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top, 0px);
    z-index: 200;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
}

.sidebar-toggle-btn:hover {
    color: var(--text);
    background: var(--bg);
}

.header-logo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    white-space: nowrap;
}

.header-search {
    flex: 1;
    max-width: 300px;
    position: relative;
    cursor: pointer;
}

.header-search input {
    width: 100%;
    padding: 6px 12px 6px 30px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
}

.header-search input:focus {
    border-color: var(--primary);
}

.header-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.header-search-kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: inherit;
    pointer-events: none;
    line-height: 1.4;
}

/* Search Command Palette */
.search-palette {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
}
.search-palette.hidden { display: none; }

.search-palette-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.search-palette-dialog {
    position: relative;
    width: 100%;
    max-width: 560px;
    background: var(--bg-card);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    animation: paletteIn 0.15s ease;
}

@keyframes paletteIn {
    from { opacity: 0; transform: scale(0.96) translateY(-8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.search-palette-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.search-palette-input-wrap svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.search-palette-input-wrap input {
    flex: 1;
    border: none;
    background: none;
    font-size: 1rem;
    color: var(--text);
    outline: none;
}

.search-palette-input-wrap input::placeholder {
    color: var(--text-muted);
}

.search-palette-input-wrap kbd {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: inherit;
    flex-shrink: 0;
}

.search-palette-results {
    max-height: 400px;
    overflow-y: auto;
}

.search-palette-group {
    padding: 8px 16px 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.search-palette-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.1s;
}

.search-palette-item:hover,
.search-palette-item.active {
    background: var(--primary);
    color: #fff;
}

.search-palette-item.active .search-palette-item-meta {
    color: rgba(255,255,255,0.7);
}

.search-palette-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.875rem;
}

.search-palette-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}

.search-palette-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.search-palette-loading {
    padding: 24px 16px;
    text-align: center;
}

.spinner-sm {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.search-palette-footer {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    color: var(--text-muted);
}

.search-palette-footer kbd {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.65rem;
    font-family: inherit;
    margin-right: 2px;
}

/* Full-page search results */
.search-result-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }

.search-result-title {
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}
.search-result-title:hover { text-decoration: underline; }

.search-result-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 2px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    align-items: center;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    text-decoration: none;
    flex-shrink: 0;
}

.user-avatar:hover {
    text-decoration: none;
    opacity: 0.9;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    z-index: 150;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.2s ease;
    scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar-nav {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.2s ease;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 12px;
}

/* Sidebar collapsed state */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
}

body.sidebar-collapsed .sidebar-divider {
    margin: 8px 6px;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 140;
}

.sidebar-overlay.active {
    display: block;
}

/* ===== Bottom Nav (mobile only) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,0.92);
    border-top: 1px solid var(--border);
    z-index: 100;
    align-items: flex-start;
    justify-content: space-around;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

body.dark-theme .bottom-nav {
    background: rgba(30,41,59,0.92);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    padding: 6px 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 500;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item:hover,
.bottom-nav-item:active {
    text-decoration: none;
}

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

.bottom-nav-item.active svg {
    stroke: var(--primary);
}

.bottom-nav-add {
    position: relative;
}

.bottom-nav-add-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 300;
    line-height: 1;
    margin-top: -18px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
    transition: transform 0.15s, background 0.15s;
}

.bottom-nav-add:active .bottom-nav-add-circle {
    transform: scale(0.92);
}

/* ===== Bottom Sheet ===== */
.bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.bottom-sheet {
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 500px;
    padding: 12px 20px 24px;
    animation: slideUp 0.25s ease;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 16px;
}

.bottom-sheet-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
    color: var(--text);
}

.bottom-sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.bottom-sheet-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.bottom-sheet-action:hover {
    text-decoration: none;
    background: var(--primary-light);
}

.bottom-sheet-action:active {
    transform: scale(0.96);
}

.bottom-sheet-action-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bsa-tasks { background: var(--primary-light); color: var(--primary); }
.bsa-invoices { background: var(--info-light); color: var(--info); }
.bsa-transactions { background: var(--success-light); color: var(--success); }
.bsa-clients { background: var(--warning-light); color: var(--warning); }

/* ===== More Sheet (mobile) ===== */
.more-sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
@media (max-width: 400px) {
    .more-sheet-grid { grid-template-columns: repeat(3, 1fr); }
}

.more-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 500;
    text-align: center;
    transition: background 0.15s;
}
.more-sheet-item:hover,
.more-sheet-item:active { background: var(--primary-light); color: var(--primary); }

.more-sheet-icon {
    font-size: 1.6rem;
    line-height: 1;
}

/* ===== Swipe Actions (Tasks) ===== */
.swipeable {
    position: relative;
    overflow: hidden;
}

.swipe-content {
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    width: 100%;
    transition: transform 0.2s ease;
    will-change: transform;
}

.swipe-content.swiping {
    transition: none;
}

.swipe-action-left,
.swipe-action-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
}

.swipe-action-left {
    left: 0;
    background: rgba(99, 102, 241, 0.1);
}

.swipe-action-right {
    right: 0;
    background: rgba(34, 197, 94, 0.1);
}

/* ===== Main Content ===== */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px;
    overflow-x: hidden;
}

.page-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 14px;
    margin-bottom: 6px;
}

.card-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 6px;
    color: var(--text);
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ===== Stat Cards (Dashboard) ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px;
    text-align: center;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); text-decoration: none; }

.btn-sm { padding: 4px 10px; font-size: 0.85rem; min-height: 30px; }
.btn-xs { padding: 3px 8px; font-size: 0.8rem; min-height: 26px; }
.btn-icon { padding: 8px; border-radius: 50%; min-width: 36px; min-height: 36px; }
.btn-block { width: 100%; justify-content: center; }

.btn-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 90;
    border: none;
    cursor: pointer;
}

.btn-fab:hover { background: var(--primary-hover); }

/* ===== Forms ===== */
.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.form-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
}

select.form-control {
    appearance: auto;
}

textarea.form-control {
    min-height: 80px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-inline {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg);
}

tr:hover td {
    background: var(--primary-light);
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-active { background: var(--success-light); color: var(--success); }
.badge-paused { background: var(--warning-light); color: var(--warning); }
.badge-archived { background: var(--bg); color: var(--text-muted); }

.badge-open { background: var(--info-light); color: var(--info); }
.badge-done { background: var(--success-light); color: var(--success); }
.badge-canceled { background: var(--bg); color: var(--text-muted); }

.badge-planned { background: var(--info-light); color: var(--info); }
.badge-sent { background: var(--warning-light); color: var(--warning); }
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-vip { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #78350f; font-weight: 700; font-size: .65rem; padding: 1px 6px; border-radius: 3px; margin-left: 4px; letter-spacing: .5px; }

.badge-low { background: var(--bg); color: var(--text-muted); }
.badge-normal { background: var(--info-light); color: var(--info); }
.badge-high { background: var(--warning-light); color: var(--warning); }
.badge-urgent { background: var(--danger-light); color: var(--danger); }

.badge-income { background: var(--success-light); color: var(--success); }
.badge-expense { background: var(--danger-light); color: var(--danger); }

/* ===== List Items ===== */
.list-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.list-item-check {
    margin-top: 2px;
    margin-right: 10px;
}

.list-item-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--success);
    cursor: pointer;
}

.list-item-body { flex: 1; min-width: 0; }

.list-item-title {
    font-weight: 500;
    font-size: 0.9rem;
    word-break: break-word;
}

.list-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.list-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    align-items: center;
}

.btn-complete-task {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
    line-height: 1;
}

.btn-complete-task:hover {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 6px 14px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.2s;
}

.tab:hover { color: var(--text); text-decoration: none; }

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ===== Filters ===== */
.filters {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filters .form-group {
    margin-bottom: 0;
}

.filters .form-control {
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* ===== Alerts / Flash ===== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 0.875rem;
}

.alert-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.alert-danger, .alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid var(--warning); }
.alert-info { background: var(--info-light); color: var(--info); border: 1px solid var(--info); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* ===== Timeline ===== */
.timeline-item {
    position: relative;
    padding: 0 0 12px 24px;
    border-left: 2px solid var(--border);
    font-size: 0.85rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

.timeline-item:last-child { border-left-color: transparent; }

.timeline-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ===== Tags ===== */
.tag {
    display: inline-block;
    padding: 1px 8px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
}

/* ===== Overdue indicator ===== */
.overdue {
    color: var(--danger);
}

.overdue .list-item-title {
    color: var(--danger);
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* ===== Quick Actions Menu ===== */
.quick-actions {
    position: fixed;
    bottom: 84px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 91;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.quick-action-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.quick-action-item:hover { background: var(--primary-light); text-decoration: none; }

/* ===== Contact card ===== */
.contact-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.contact-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.contact-card-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.contact-card-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.contact-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.contact-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg-card);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid var(--border);
}

.contact-link:hover {
    color: var(--primary);
    border-color: var(--primary);
    text-decoration: none;
}

/* ===== Charts (simple) ===== */
.chart-container {
    position: relative;
    width: 100%;
    height: 200px;
    margin-bottom: 16px;
}

.chart-bar-group {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 160px;
    padding: 0 4px;
}

.chart-bar {
    flex: 1;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    position: relative;
}

.chart-bar-label {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.chart-bar-value {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

/* ===== Auth Page ===== */
body.auth-layout {
    padding-top: 0;
    padding-bottom: 0;
}

.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    position: relative;
    overflow: hidden;
    max-width: none;
    margin: 0;
    box-sizing: border-box;
}
.auth-page::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 20% 50%, rgba(255,255,255,0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 20%, rgba(255,255,255,0.06) 0%, transparent 40%),
                radial-gradient(ellipse at 40% 80%, rgba(255,255,255,0.04) 0%, transparent 40%);
    pointer-events: none;
}

.auth-page .alert {
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 1;
    border: none;
    backdrop-filter: blur(10px);
}
.auth-page .alert-error, .auth-page .alert-danger {
    background: rgba(239,68,68,0.15);
    color: #fecaca;
    border: 1px solid rgba(239,68,68,0.3);
}
.auth-page .alert-success {
    background: rgba(34,197,94,0.15);
    color: #bbf7d0;
    border: 1px solid rgba(34,197,94,0.3);
}

.auth-card {
    background: rgba(255,255,255,0.95);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 0 0 1px rgba(255,255,255,0.2);
    padding: 40px 32px 32px;
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(20px);
}

.auth-logo {
    text-align: center;
    margin-bottom: 8px;
}
.auth-logo img {
    border-radius: 16px;
    background: #ffffff;
    padding: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 0 0 1px rgba(255,255,255,0.3);
}

.auth-title {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 28px;
    color: #1e293b;
    letter-spacing: 0.5px;
}
.auth-title-accent {
    color: #6366f1;
    font-weight: 800;
}

.auth-card .form-group label {
    color: #475569;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.auth-card .form-control {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    color: #1e293b;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.auth-card .form-control:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
    background: #fff;
}
.auth-card .form-control::placeholder {
    color: #94a3b8;
}

.auth-card .btn-primary {
    margin-top: 8px;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    letter-spacing: 0.3px;
    transition: transform 0.15s, box-shadow 0.15s;
}
.auth-card .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99,102,241,0.4);
}
.auth-card .btn-primary:active {
    transform: translateY(0);
}

/* Dark theme auth page — keep identical to light theme */
.dark-theme .auth-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.dark-theme .auth-card {
    background: rgba(255,255,255,0.95);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 0 0 1px rgba(255,255,255,0.2);
}
.dark-theme .auth-title {
    color: #1e293b;
}
.dark-theme .auth-title-accent {
    color: #6366f1;
}
.dark-theme .auth-card .form-group label {
    color: #475569;
}
.dark-theme .auth-card .form-control {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #1e293b;
}
.dark-theme .auth-card .form-control:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
    background: #fff;
}
.dark-theme .auth-card .form-control::placeholder {
    color: #94a3b8;
}

.password-wrap {
    position: relative;
}
.password-wrap .form-control {
    padding-right: 44px;
}
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
}
.password-toggle:hover {
    color: var(--text);
}

/* Password toggle on auth page */
.auth-page .password-toggle,
.dark-theme .auth-page .password-toggle {
    color: #94a3b8;
}
.auth-page .password-toggle:hover,
.dark-theme .auth-page .password-toggle:hover {
    color: #475569;
}

/* ===== Responsive ===== */

/* Mobile: sidebar hidden by default, shown as overlay */
@media (max-width: 767px) {
    body.has-sidebar {
        padding-left: 0 !important;
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
    }

    body.sidebar-collapsed .sidebar-label {
        opacity: 1;
        width: auto;
    }

    body.sidebar-collapsed .sidebar-link {
        justify-content: flex-start;
        padding: 8px 12px;
    }

    .header-search {
        max-width: 160px;
    }

    .header-search-kbd {
        display: none;
    }

    .search-palette {
        padding-top: 0;
    }

    .search-palette-dialog {
        max-width: 100%;
        border-radius: 0;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }

    .search-palette-results {
        flex: 1;
        max-height: none;
    }

    .search-palette-footer {
        display: none;
    }

    /* Hide FAB on mobile — replaced by bottom nav "+" */
    .btn-fab,
    .quick-actions {
        display: none !important;
    }

    /* Show bottom nav on mobile */
    .bottom-nav {
        display: flex;
    }

    .bottom-nav-item {
        min-height: 56px;
        padding: 8px 4px;
    }

    /* Enforce minimum 44px touch targets on mobile */
    .btn-xs {
        min-height: 44px;
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .btn-sm {
        min-height: 38px;
        padding: 6px 12px;
    }

    .btn {
        min-height: 38px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    .btn-complete-task {
        width: 44px;
        height: 44px;
    }

    .pagination .btn {
        min-width: 44px;
        min-height: 44px;
        padding: 8px 10px;
    }

    /* Rule 2 — Flex-wrap for action button containers inside cards */
    .card .d-flex.gap-1 {
        flex-wrap: wrap;
    }
    .btn-group-wrap {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Rule 4 — Filters: override form's d-flex to grid on mobile */
    .filters {
        display: block;
    }
    .filters form {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .filters form .form-group:first-of-type {
        grid-column: 1 / -1;
    }
    .filters .form-control {
        width: 100%;
        font-size: 1rem;
    }
    .filters input[type="date"] {
        width: 100%;
        box-sizing: border-box;
    }

    /* Rule 5 — Prevent iOS auto-zoom on input focus (min 16px) */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Rule 6 — Tighter card padding on mobile */
    .card {
        padding: 10px;
        margin-bottom: 6px;
    }

    /* Rule 7 — Horizontal scroll for tables */
    .table-wrap {
        border-radius: var(--radius);
        border: 1px solid var(--border);
    }

    /* Rule 8 — Page title stacks vertically on mobile */
    .page-title {
        flex-direction: column;
        align-items: flex-start;
    }
    .page-title .d-flex {
        align-self: stretch;
    }
    .page-title .d-flex .btn,
    .page-title a.btn,
    .page-title button.btn {
        flex: 1;
        justify-content: center;
        text-align: center;
    }

    /* Rule 9 — Form row: 3rd field spans full width in 2-col grid */
    .form-row > :last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    /* Rule 10 — Tabs: smaller padding, no shrink */
    .tab {
        padding: 8px 12px;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    .tabs {
        padding-bottom: 2px;
    }

    /* Rule 11 — Hide elements on mobile */
    .hide-mobile {
        display: none !important;
    }
}

@media (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .modal {
        border-radius: var(--radius-lg);
        margin-bottom: 0;
    }

    .modal-overlay {
        align-items: center;
    }

    .form-row {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

@media (min-width: 1024px) {
    .main {
        max-width: 1100px;
    }
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mr-1 { margin-right: 8px; }
.ml-auto { margin-left: auto; }
.d-flex { display: flex; }
.gap-05 { gap: 4px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Print ===== */
@media print {
    .header, .bottom-nav, .sidebar, .sidebar-overlay, .btn-fab, .quick-actions, .bottom-sheet-overlay { display: none; }
    body { padding: 0; }
}

/* --- Client searchable autocomplete --- */
.client-select-wrap{position:relative}
.client-search-dropdown{position:absolute;top:100%;left:0;right:0;background:var(--bg-card);color:var(--text);border:1px solid var(--border);border-radius:6px;max-height:220px;overflow-y:auto;z-index:999;box-shadow:0 4px 16px rgba(0,0,0,.25);margin-top:2px}
.client-search-option{padding:8px 12px;cursor:pointer;font-size:.9rem;border-bottom:1px solid var(--border)}
.client-search-option:last-child{border-bottom:none}
.client-search-option:hover,.client-search-option.ca-focused{background:var(--bg);color:var(--text)}

/* --- Requisites --- */
.req-grid{display:grid;gap:16px;grid-template-columns:repeat(auto-fill,minmax(300px,1fr))}
.req-card{padding:16px}
.req-card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;gap:8px;flex-wrap:wrap}
.req-card-header strong{font-size:1rem}
.req-content{white-space:pre-wrap;font-size:.85rem;margin:0 0 10px 0;padding:10px;background:var(--bg,#f8f8f8);border-radius:6px;line-height:1.5;max-height:200px;overflow-y:auto;word-break:break-all}
.req-delete-form{text-align:right}
.req-delete-btn{color:var(--danger,#e53935);border-color:var(--danger,#e53935)}
.req-textarea{font-family:monospace;font-size:.9rem;resize:vertical}
@media(max-width:600px){.req-grid{grid-template-columns:1fr}}
/* Requisite type selector */
.req-type-group{display:flex;flex-wrap:wrap;gap:8px}
.req-type-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 12px;border:1.5px solid var(--border,#ddd);border-radius:20px;cursor:pointer;font-size:.875rem;transition:all .15s;user-select:none}
.req-type-btn input[type=radio]{display:none}
.req-type-btn.active{border-color:var(--primary,#1976d2);background:var(--primary,#1976d2);color:#fff}
.req-type-btn:hover:not(.active){border-color:var(--primary,#1976d2);color:var(--primary,#1976d2)}
/* Currency quick pick */
.req-currency-suggestions{display:flex;flex-wrap:wrap;gap:4px}
.req-cur-btn{cursor:pointer;font-size:.75rem;padding:3px 8px;border:1px solid var(--border,#ddd);border-radius:12px;background:none;transition:all .15s}
.req-cur-btn:hover{border-color:var(--primary,#1976d2);color:var(--primary,#1976d2)}
/* Crypto hint */
.req-crypto-hint{margin-top:6px;padding:8px 12px;background:rgba(25,118,210,.07);border-radius:6px;font-size:.85rem;color:var(--text-muted,#888)}
/* Requisite badges */
.badge-currency{background:var(--primary,#1976d2);color:#fff;font-size:.7rem;padding:2px 7px;border-radius:10px;font-weight:600}
.badge-primary-star{background:#f59e0b;color:#fff;font-size:.7rem;padding:2px 8px;border-radius:10px;font-weight:600}
.req-set-primary{color:var(--text-muted,#888);font-size:.72rem;border:none;background:none;cursor:pointer;padding:2px 6px;border-radius:10px;transition:all .15s}
.req-set-primary:hover{background:var(--primary,#1976d2);color:#fff}
.req-type-icon{font-size:1.1rem}
/* Facture Profiles */
.fp-info-banner{display:flex;align-items:flex-start;gap:10px;padding:12px 16px;background:rgba(25,118,210,.07);border:1px solid rgba(25,118,210,.2);border-radius:8px;margin-bottom:16px;font-size:.9rem;line-height:1.5}
.fp-info-icon{font-size:1.3rem;flex-shrink:0;margin-top:1px}
.fp-info-banner a{color:var(--primary,#1976d2);text-decoration:none;font-weight:500}
.fp-info-banner a:hover{text-decoration:underline}
.fp-card{padding:0}
.fp-card-body{display:flex;align-items:center;gap:14px;padding:14px 16px;flex-wrap:wrap}
.fp-card-info{flex:1;min-width:0}
.fp-logo-thumb{width:56px;height:56px;border-radius:8px;overflow:hidden;flex-shrink:0;border:1px solid var(--border,#ddd);display:flex;align-items:center;justify-content:center}
.fp-logo-thumb-img{width:100%;height:100%;object-fit:contain}
.fp-logo-placeholder{background:var(--primary,#1976d2);color:#fff;font-weight:700;font-size:1.1rem}
/* Logo upload preview */
.fp-logo-preview{display:flex;align-items:center;gap:12px;margin-bottom:8px;padding:8px;background:var(--bg,#f8f8f8);border-radius:8px}
.fp-logo-img{height:60px;max-width:160px;object-fit:contain;border-radius:4px}
.fp-logo-remove{display:flex;align-items:center;gap:6px;cursor:pointer;font-size:.85rem;color:var(--danger,#e53935)}
@media(max-width:600px){.fp-card-body{flex-wrap:wrap}.fp-logo-thumb{width:44px;height:44px}}

/* --- Currency Rates --- */
.rates-matrix{width:100%;border-collapse:collapse;font-size:.85rem}
.rates-matrix th,.rates-matrix td{padding:6px 10px;border:1px solid var(--border);text-align:center;white-space:nowrap}
.rates-matrix th{background:var(--bg);font-weight:600;font-size:.8rem}
.rates-corner{background:var(--bg);text-align:left;font-size:.75rem;color:var(--text-muted)}
.rates-row-label{background:var(--bg);text-align:left}
.rates-same{background:var(--bg);color:var(--text-muted)}
.rates-missing{font-size:.75rem}
.rates-value{font-variant-numeric:tabular-nums}
.rates-chart-wrap{position:relative;height:220px}
.rates-actions-row{display:grid;grid-template-columns:1fr 1fr;gap:16px}
@media(max-width:640px){.rates-actions-row{grid-template-columns:1fr}}
.rates-cron-card{margin-top:16px}
.rates-cron-cmd{display:block;background:var(--bg);border:1px solid var(--border);border-radius:6px;padding:8px 12px;font-size:.8rem;word-break:break-all;margin-top:8px;font-family:monospace;color:var(--text)}
/* --- KPI chips row --- */
.kpi-row{display:flex;flex-wrap:wrap;gap:10px;margin-bottom:16px}
.kpi-chip{display:flex;align-items:center;gap:6px;padding:8px 14px;border-radius:20px;background:var(--bg-card,#fff);border:1px solid var(--border,#e0e0e0);font-size:.85rem;flex:1;min-width:140px;color:var(--text)}
.kpi-chip-icon{font-size:1rem}
.kpi-chip-label{color:var(--text-muted,#888);flex:1}
.kpi-chip-value{font-weight:700;font-size:.95rem;color:var(--text)}
.kpi-chip-primary{border-color:var(--primary,#1976d2);background:rgba(25,118,210,0.10)}
.kpi-chip-warn{border-color:var(--warning,#f59e0b);background:rgba(245,158,11,0.10)}
.kpi-chip-danger{border-color:var(--danger,#e53935);background:rgba(229,57,53,0.10)}
.kpi-chip-success{border-color:var(--success,#43a047);background:rgba(67,160,71,0.10)}
body.dark-theme .kpi-chip{background:var(--bg-card,#1e293b)}
body.dark-theme .kpi-chip-primary{background:rgba(129,140,248,0.15)}
body.dark-theme .kpi-chip-warn{background:rgba(245,158,11,0.15)}
body.dark-theme .kpi-chip-danger{background:rgba(229,57,53,0.18)}
body.dark-theme .kpi-chip-success{background:rgba(67,160,71,0.15)}
.stat-card-warn{border-left:3px solid var(--warning,#f59e0b)}

/* Clickable stat cards */
a.stat-card-link{text-decoration:none;color:inherit;transition:transform .15s,box-shadow .15s;display:block}
a.stat-card-link:hover{transform:translateY(-1px);box-shadow:0 4px 12px rgba(0,0,0,.12);text-decoration:none}
a.stat-card-link:hover .stat-label{color:var(--primary)}

/* Period selector */
.period-selector{display:flex;gap:4px;margin-bottom:16px;flex-wrap:wrap}
.period-tab{padding:6px 14px;border-radius:var(--radius);font-size:.85rem;color:var(--text-muted);text-decoration:none;border:1px solid var(--border);transition:all .2s}
.period-tab:hover{color:var(--text);border-color:var(--text-muted)}
.period-tab.active{background:var(--primary);color:#fff;border-color:var(--primary)}

/* Forecast widget */
.forecast-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:var(--spacing-md)}
.forecast-item{text-align:center}
.forecast-value{font-size:1.25rem;font-weight:700;margin-bottom:2px}
.forecast-label{font-size:.8rem;color:var(--text-muted)}
.forecast-breakdown{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;padding-top:8px;border-top:1px solid var(--border);font-size:.78rem;color:var(--text-muted)}
@media(max-width:768px){.forecast-grid{grid-template-columns:1fr}}

/* --- Push notification bell --- */
.notif-bell{background:none;border:none;cursor:pointer;padding:4px 6px;border-radius:8px;color:var(--text-muted);display:flex;align-items:center;transition:color .2s,background .2s}
.notif-bell:hover{background:var(--bg-input);color:var(--text)}
.notif-bell.notif-active{color:var(--primary)}
.notif-bell.notif-active svg{fill:var(--primary);stroke:var(--primary)}
.notif-bell.hidden{display:none}

/* --- Dashboard Charts --- */
.charts-row{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px}
@media(max-width:480px){.charts-row{grid-template-columns:1fr}}
.chart-card{padding:14px}
.chart-donut-wrap{display:flex;justify-content:center;padding:8px 0}
.chart-donut-wrap canvas{max-width:160px;max-height:160px}
.chart-legend{display:flex;flex-direction:column;gap:6px;margin-top:4px}
.chart-legend-item{display:flex;align-items:center;gap:6px;font-size:.8rem;min-width:0}
.chart-legend-dot{width:10px;height:10px;border-radius:50%;flex-shrink:0}
.chart-legend-net{border-top:1px solid var(--border);padding-top:6px;margin-top:2px}

/* --- Pagination --- */
.pagination{display:flex;gap:4px;flex-wrap:wrap;justify-content:center;margin-top:16px;padding-bottom:8px}

/* --- Dashboard period filter --- */
.dashboard-filter{margin-bottom:14px}
.period-tabs{display:flex;gap:6px;flex-wrap:wrap}
.period-tab{background:none;border:1px solid var(--border);border-radius:20px;padding:5px 14px;cursor:pointer;font-size:.82rem;color:var(--text-muted);transition:all .2s;line-height:1.4}
.period-tab:hover{border-color:var(--primary);color:var(--primary)}
.period-tab.active{background:var(--primary);border-color:var(--primary);color:#fff}
.period-custom{display:flex;align-items:center;gap:8px;margin-top:10px;flex-wrap:wrap}
.stat-period{font-size:.72rem;color:var(--text-muted);margin-top:2px}

/* ===== Phase 1: Page Transition Animation ===== */
.main{animation:pageIn .2s ease}
@keyframes pageIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}

/* ===== Client Avatars ===== */
.avatar-circle{width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:.85rem;flex-shrink:0;letter-spacing:.5px}
.avatar-circle-lg{width:48px;height:48px;font-size:1.1rem}

/* ===== Breadcrumbs ===== */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .78rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.breadcrumbs a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color .15s;
}
.breadcrumbs a:hover {
    color: var(--primary);
    text-decoration: none;
}
.breadcrumb-sep {
    color: var(--border);
    font-size: .65rem;
    margin: 0 2px;
}
.breadcrumb-current {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== Empty States Enhanced ===== */
.empty-state svg{width:64px;height:64px;margin-bottom:12px;opacity:.4;color:var(--text-muted)}

/* ===== Kanban Board ===== */
.kanban-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    min-height: 300px;
}
.kanban-column {
    flex: 1;
    min-width: 250px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 10px;
}
.kanban-column-header,
.kanban-column-title {
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 10px;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
}
.kanban-column-count {
    font-size: .7rem;
    background: var(--border);
    border-radius: 10px;
    padding: 1px 8px;
    color: var(--text-secondary);
}
.kanban-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: grab;
    transition: box-shadow .15s, transform .15s;
    border-left: 3px solid var(--primary);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .5; transform: rotate(2deg); }
.kanban-card-title {
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
    text-decoration: none;
    display: block;
}
.kanban-card-title:hover { color: var(--primary); text-decoration: none; }
.kanban-card-meta {
    font-size: .7rem;
    color: var(--text-secondary);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.kanban-column[data-status="done"] .kanban-card { border-left-color: var(--success); }
.kanban-column[data-status="in_progress"] .kanban-card { border-left-color: var(--warning); }
.kanban-complete-btn{width:26px;height:26px;border-radius:50%;background:var(--success-light);color:var(--success);border:2px solid var(--success);display:flex;align-items:center;justify-content:center;font-size:.7rem;cursor:pointer;transition:all .15s;flex-shrink:0;padding:0;line-height:1}
.kanban-complete-btn:hover{background:var(--success);color:#fff}
.view-toggle {
    display: flex;
    gap: 4px;
}
.view-toggle-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: .8rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all .15s;
}
.view-toggle-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== Bulk Actions Toolbar ===== */
.bulk-toolbar{position:fixed;bottom:0;left:0;right:0;background:var(--bg-card);border-top:2px solid var(--primary);padding:10px 16px;display:flex;align-items:center;justify-content:center;gap:10px;z-index:150;animation:slideUp .2s ease;box-shadow:0 -4px 12px rgba(0,0,0,.15)}
.bulk-toolbar-count{font-size:.85rem;font-weight:600;margin-right:8px}
.bulk-check{width:18px;height:18px;accent-color:var(--primary);cursor:pointer}

/* ===== Saved Filters ===== */
.saved-filters{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:10px}
.saved-filter-chip{display:inline-flex;align-items:center;gap:4px;padding:4px 12px;background:var(--primary-light);color:var(--primary);border-radius:16px;font-size:.78rem;font-weight:500;cursor:pointer;border:none;transition:background .15s}
.saved-filter-chip:hover{background:var(--primary);color:#fff;text-decoration:none}
.saved-filter-chip .chip-x{font-size:.9rem;margin-left:2px;cursor:pointer;opacity:.6}
.saved-filter-chip .chip-x:hover{opacity:1}

/* ===== Calendar ===== */
.calendar-nav{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;gap:8px}
.calendar-nav-title{font-size:1rem;font-weight:600;min-width:140px;text-align:center}
.calendar-nav-btn{background:none;border:1px solid var(--border);border-radius:var(--radius-sm);padding:4px 10px;cursor:pointer;font-size:.85rem;color:var(--text);transition:border-color .15s,color .15s}
.calendar-nav-btn:hover{border-color:var(--primary);color:var(--primary)}
.calendar-view-toggle{display:flex;gap:0}
.calendar-view-toggle .cal-view-btn{border-radius:0}
.calendar-view-toggle .cal-view-btn:first-child{border-radius:var(--radius-sm) 0 0 var(--radius-sm)}
.calendar-view-toggle .cal-view-btn:last-child{border-radius:0 var(--radius-sm) var(--radius-sm) 0;margin-left:-1px}
.calendar-view-toggle .cal-view-btn.active{background:var(--primary);border-color:var(--primary);color:#fff}
@media(max-width:600px){
    .calendar-nav{flex-wrap:wrap;gap:4px}
    .calendar-nav-btn{padding:6px 10px;font-size:.8rem;min-height:44px;display:inline-flex;align-items:center}
    .calendar-nav-title{font-size:.9rem}
}
.calendar-header{display:grid;grid-template-columns:repeat(7,1fr);text-align:center;font-size:.7rem;font-weight:600;color:var(--text-muted);margin-bottom:4px;text-transform:uppercase}
/* Month view */
.calendar-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:2px}
.calendar-cell{min-height:72px;padding:4px;border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--bg-card);cursor:pointer;font-size:.75rem;position:relative;transition:background .15s,border-color .15s}
.calendar-cell:hover{background:var(--primary-light);border-color:var(--primary)}
.calendar-cell.other-month{opacity:.3;pointer-events:none}
.calendar-cell.today{border-color:var(--primary);background:var(--primary-light)}
.calendar-cell.today .calendar-day-num{color:var(--primary)}
.calendar-cell.empty .calendar-day-num{opacity:.6}
.calendar-day-num{font-weight:600;font-size:.75rem;margin-bottom:3px}
/* Event chips */
.calendar-event{display:block;padding:1px 4px;border-radius:3px;font-size:.65rem;margin-bottom:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-decoration:none;color:#fff;line-height:1.4}
.calendar-event:hover{opacity:.85;text-decoration:none}
.calendar-event-task{background:var(--primary)}
.calendar-event-invoice{background:var(--warning,#e5a82a);color:#fff}
.calendar-event-overdue{background:var(--danger)}
.cal-ev-time{opacity:.85;font-size:.6rem;margin-right:3px}
/* Empty day hint */
.calendar-empty-hint{position:absolute;bottom:4px;right:5px;font-size:.65rem;color:var(--text-muted);opacity:0;transition:opacity .15s;user-select:none}
.calendar-cell.empty:hover .calendar-empty-hint{opacity:1}
/* Week view */
.calendar-grid-week{grid-template-rows:1fr}
.calendar-week-cell{min-height:180px;padding:6px;display:flex;flex-direction:column;gap:3px}
.calendar-event-week{white-space:normal;overflow:visible;text-overflow:unset;font-size:.72rem;padding:3px 6px;line-height:1.35}
/* Week header with date numbers */
.calendar-header.calendar-header-week div{display:flex;flex-direction:column;align-items:center;gap:1px;padding:4px 0}
.calendar-header.calendar-header-week div strong{font-size:.9rem;font-weight:700}
.calendar-header.calendar-header-week div span{font-size:.65rem;font-weight:600;color:var(--text-muted);text-transform:uppercase}
@media(max-width:600px){.calendar-cell{min-height:48px;font-size:.65rem}.calendar-event{font-size:.6rem}.calendar-week-cell{min-height:120px}}

/* ===== Factures ===== */
.facture-info-banner{display:flex;align-items:flex-start;gap:8px;padding:10px 14px;background:var(--primary-light);border:1px solid var(--primary);border-radius:var(--radius);margin-bottom:12px;font-size:.82rem;line-height:1.45}
.facture-info-icon{font-size:1.1rem;flex-shrink:0;margin-top:1px;color:var(--primary)}
.facture-suggest-banner{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px;background:var(--primary-light);border:1px solid var(--primary);border-radius:var(--radius);margin-bottom:12px;flex-wrap:wrap}

/* ===== File Attachments ===== */
.dropzone{border:2px dashed var(--border);border-radius:var(--radius);padding:24px;text-align:center;color:var(--text-muted);font-size:.85rem;cursor:pointer;transition:border-color .2s,background .2s}
.dropzone:hover,.dropzone.dragover{border-color:var(--primary);background:var(--primary-light)}
.dropzone-icon{font-size:2rem;margin-bottom:6px;opacity:.4}
.file-list{margin-top:10px}
.file-item{display:flex;align-items:center;justify-content:space-between;padding:6px 10px;background:var(--bg);border-radius:var(--radius-sm);margin-bottom:4px;font-size:.82rem}
.file-item-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.file-item-size{color:var(--text-muted);font-size:.72rem;margin:0 8px}

/* ===== Audit Log ===== */
.audit-row{padding:8px 0;border-bottom:1px solid var(--border);font-size:.82rem}
.audit-row:last-child{border-bottom:none}
.audit-action{font-weight:500}
.audit-entity{color:var(--primary)}
.audit-time{color:var(--text-muted);font-size:.72rem;white-space:nowrap}
.audit-ip{color:var(--text-muted);font-size:.68rem}
/* Audit log v2 */
.audit-table{width:100%;font-size:.875rem}
.audit-table td,.audit-table th{vertical-align:middle;padding:8px 10px}
.audit-th-time{width:90px}
.audit-th-id{width:56px;text-align:center}
.audit-date{display:block;font-size:.8rem;color:var(--text)}
.audit-hour{display:block;font-size:.7rem;color:var(--text-muted)}
.audit-action-badge{display:inline-block;padding:2px 8px;border-radius:10px;font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.03em}
.audit-action-create{background:rgba(22,163,74,.12);color:#16a34a}
.audit-action-update{background:rgba(59,130,246,.12);color:#3b82f6}
.audit-action-delete{background:rgba(220,38,38,.12);color:#dc2626}
.audit-action-paid{background:rgba(245,158,11,.12);color:#d97706}
.audit-entity-badge{display:inline-block;padding:2px 7px;border-radius:8px;font-size:.72rem;background:var(--bg);border:1px solid var(--border);color:var(--text-muted)}
.audit-id-cell{text-align:center}
.audit-id-link{color:var(--primary);font-weight:600;font-size:.85rem;text-decoration:none}
.audit-id-link:hover{text-decoration:underline}
.audit-details-cell{max-width:340px;font-size:.8rem;color:var(--text-muted);line-height:1.5}
.audit-details-text .audit-field{color:var(--text);font-weight:500}
.audit-details-text .audit-old{color:var(--danger,#e53935);text-decoration:line-through}
.audit-details-text .audit-new{color:var(--success,#4caf50);font-weight:500}
/* Audit search */
.audit-search-wrap{position:relative;flex:1;min-width:160px;max-width:280px}
.audit-search-clear{position:absolute;right:8px;top:50%;transform:translateY(-50%);color:var(--text-muted);font-size:.8rem;text-decoration:none;line-height:1}
.audit-search-clear:hover{color:var(--danger)}
.search-clear-btn{position:absolute;right:6px;top:50%;transform:translateY(-50%);background:none;border:none;color:var(--text-muted);font-size:1.1rem;cursor:pointer;padding:2px 4px;line-height:1}
.search-clear-btn:hover{color:var(--danger)}

/* ===== Settings Page ===== */
.settings-logo-row{display:flex;align-items:flex-start;gap:16px;margin-bottom:20px;flex-wrap:wrap}
.settings-logo-wrap{flex-shrink:0}
.settings-logo-img{width:80px;height:80px;object-fit:contain;border-radius:10px;border:1px solid var(--border)}
.settings-logo-placeholder{width:80px;height:80px;border-radius:10px;background:var(--primary);color:#fff;display:flex;align-items:center;justify-content:center;font-size:1.5rem;font-weight:700}
.settings-logo-fields{flex:1;min-width:0}
.settings-divider{border:none;border-top:1px solid var(--border);margin:20px 0}
.settings-section-title{font-size:.75rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--text-muted);padding:20px 0 8px;margin:0}
.settings-cards-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:16px}
.settings-action-card{display:flex;gap:16px;align-items:flex-start;padding:16px}
.settings-action-icon{font-size:1.6rem;flex-shrink:0;margin-top:2px}
@media(max-width:600px){.settings-logo-row{flex-direction:column}.settings-logo-wrap{margin:0 auto}}
/* ===== Dashboard Widgets ===== */
.widget{position:relative}
.widget-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
.widget-drag{cursor:grab;color:var(--text-muted);padding:2px 4px;opacity:.4;transition:opacity .2s}
.widget-drag:hover{opacity:1}
.widget.dragging{opacity:.5;outline:2px dashed var(--primary)}
.widget-toggle{background:none;border:none;cursor:pointer;color:var(--text-muted);font-size:.8rem;padding:2px 6px}

/* ===== Client Portal ===== */
.portal-header{background:var(--bg-card);padding:16px 20px;border-bottom:1px solid var(--border);text-align:center}
.portal-logo{font-size:1.1rem;font-weight:700;color:var(--primary)}
.portal-main{max-width:800px;margin:0 auto;padding:20px}
.portal-card{background:var(--bg-card);border-radius:var(--radius);box-shadow:var(--shadow);padding:16px;margin-bottom:12px}

/* ===== API Settings ===== */
.api-key-display{font-family:monospace;font-size:.85rem;padding:8px 12px;background:var(--bg);border-radius:var(--radius-sm);border:1px solid var(--border);word-break:break-all}

/* ===== Recurring Task Indicator ===== */
.recurring-icon{color:var(--primary);font-size:.75rem;margin-left:4px;vertical-align:middle}

/* ===== Status in_progress badge ===== */
.badge-in_progress{background:var(--primary-light);color:var(--primary)}

/* ===== Quill Editor ===== */
.ql-container{font-size:14px;font-family:inherit}
.ql-editor{min-height:100px}
.ql-toolbar.ql-snow{border-color:var(--border);border-radius:var(--radius-sm) var(--radius-sm) 0 0;background:var(--bg)}
.ql-container.ql-snow{border-color:var(--border);border-radius:0 0 var(--radius-sm) var(--radius-sm)}
.ql-editor img{max-width:100%;height:auto;border-radius:4px;margin:8px 0}

/* ===== TomSelect overrides ===== */
.ts-wrapper .ts-control{border-color:var(--border);border-radius:var(--radius-sm);min-height:38px;background:var(--bg-input)}
.ts-wrapper .ts-dropdown{border-color:var(--border);border-radius:var(--radius-sm)}
.ts-wrapper .ts-dropdown .option.active{background:var(--primary);color:#fff}

/* ===== Media Library ===== */
.media-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:16px}
.media-item{background:var(--bg-card);border-radius:var(--radius);box-shadow:var(--shadow);overflow:hidden;display:flex;flex-direction:column;position:relative}
.media-item.selected{box-shadow:0 0 0 2px var(--primary)}
.media-thumb{aspect-ratio:1;overflow:hidden;display:flex;align-items:center;justify-content:center;background:var(--bg)}
.media-thumb img{width:100%;height:100%;object-fit:cover;transition:transform .2s}
.media-thumb:hover img{transform:scale(1.05)}
.media-file-icon{display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;height:100%;font-size:.85rem;font-weight:700;color:var(--text-muted);text-transform:uppercase;gap:4px}
.media-file-icon-pdf{color:#e44}
.media-preview-hint{font-size:1.5rem;opacity:.5}
/* Checkbox */
.media-select-wrap{position:absolute;top:6px;left:6px;z-index:2;background:var(--bg-card);border-radius:3px;padding:2px;opacity:0;transition:opacity .15s}
.media-item:hover .media-select-wrap,.media-item.selected .media-select-wrap{opacity:1}
.media-select-wrap input{cursor:pointer;width:16px;height:16px}
.media-info{padding:10px 12px;display:flex;flex-direction:column;gap:4px}
/* Name + rename */
.media-name-wrap{display:flex;align-items:center;gap:4px}
.media-name-display{font-size:.8rem;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0}
.media-name-input{font-size:.8rem;flex:1;padding:2px 4px;height:auto}
.media-rename-btn{opacity:0;transition:opacity .15s;flex-shrink:0}
.media-item:hover .media-rename-btn{opacity:.7}
.media-rename-btn:hover{opacity:1}
/* Description */
.media-desc-input{border:none;background:transparent;font-size:.75rem;color:var(--text-secondary);width:100%;padding:2px 0;border-bottom:1px dashed var(--border)}
.media-desc-input:focus{outline:none;border-bottom-color:var(--primary)}
/* Category */
.media-cat-wrap{min-height:20px}
.media-cat-badge{display:inline-block;font-size:.65rem;padding:1px 6px;background:var(--primary-light);color:var(--primary);border-radius:var(--radius-sm);cursor:pointer;border:1px solid var(--primary);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.media-cat-badge.media-cat-empty{background:transparent;border-color:var(--border);color:var(--text-muted)}
.media-cat-badge:hover{opacity:.8}
.media-cat-select{font-size:.75rem;padding:2px 4px;height:auto}
/* Meta + actions */
.media-meta{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.media-actions{display:flex;gap:4px;margin-top:4px;flex-wrap:wrap}
.media-share-link{padding:4px 12px 8px}
.media-share-link input{font-size:.7rem;padding:4px 6px;height:auto}
/* Lightbox */
.media-lightbox{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.88);z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px}
.media-lightbox.hidden{display:none}
.media-lightbox-inner{position:relative;max-width:92vw;width:100%;max-height:92vh;display:flex;flex-direction:column;align-items:center}
.media-lightbox-inner img{max-width:90vw;max-height:80vh;border-radius:var(--radius);object-fit:contain}
.media-lightbox-close{position:absolute;top:-14px;right:-14px;background:var(--bg-card);border:none;width:32px;height:32px;border-radius:50%;font-size:18px;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:var(--shadow-md);z-index:10;color:var(--text)}
.media-lightbox-name{color:#fff;margin-top:12px;font-size:.85rem;text-align:center;word-break:break-word}
/* Batch toolbar */
.media-batch-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 12px;background:var(--primary-light);border:1px solid var(--primary);border-radius:var(--radius);margin-bottom:12px;position:sticky;top:0;z-index:50}
@media(max-width:600px){.media-grid{grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:10px}.media-select-wrap{opacity:1}}

/* Media upload progress */
.media-item-uploading{animation:mediaUploadPulse 1.5s ease-in-out infinite}
@keyframes mediaUploadPulse{0%,100%{opacity:1}50%{opacity:.7}}
.media-upload-spinner{position:absolute;top:0;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.15);z-index:2}
.media-thumb{position:relative}
.spinner-ring{width:36px;height:36px;border:3px solid rgba(255,255,255,0.3);border-top-color:#fff;border-radius:50%;animation:spinRing .8s linear infinite}
@keyframes spinRing{to{transform:rotate(360deg)}}

/* File-type icons */
.media-file-icon svg{opacity:.9}
.media-file-icon span{font-size:.72rem;letter-spacing:.5px;margin-top:2px}
.media-file-icon-pdf{color:#e5484d}
.media-file-icon-text{color:#64748b}
.media-file-icon-doc{color:#2563eb}
.media-file-icon-sheet{color:#16a34a}
.media-file-icon-zip{color:#d97706}
.media-file-icon-other{color:var(--text-muted)}
/* Flash a tile just added / matched after upload */
.media-item-flash{animation:mediaFlash 1.2s ease-out}
@keyframes mediaFlash{0%{box-shadow:0 0 0 3px var(--primary)}100%{box-shadow:var(--shadow)}}
/* Text reader in lightbox */
.media-text-reader{background:var(--bg-card);color:var(--text);border-radius:var(--radius);padding:18px 20px;max-height:78vh;overflow:auto;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.82rem;line-height:1.5;width:100%}
/* Pagination */
.media-pagination{display:flex;align-items:center;justify-content:center;gap:6px;flex-wrap:wrap;margin-top:20px}
.media-pagination .page-num{display:inline-flex;align-items:center;justify-content:center;min-width:32px;height:32px;padding:0 8px;border:1px solid var(--border);border-radius:var(--radius-sm);color:var(--text-secondary);font-size:.85rem;text-decoration:none}
.media-pagination .page-num:hover{border-color:var(--primary);color:var(--primary)}
.media-pagination .page-num.active{background:var(--primary);color:#fff;border-color:var(--primary)}
.media-pagination .page-ellipsis{color:var(--text-muted);padding:0 2px}
/* Media ↔ client link */
.media-client-wrap{min-height:18px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
.media-client-badge{display:inline-block;font-size:.65rem;padding:1px 7px;background:var(--primary-light);color:var(--primary);border-radius:var(--radius-sm);cursor:pointer;border:1px solid var(--primary);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.media-client-badge.media-client-empty{background:transparent;border-color:var(--border);color:var(--text-muted)}
.media-client-badge:hover{opacity:.85}
.media-client-filter{font-size:.72rem;text-decoration:none;opacity:.55;line-height:1}
.media-client-filter:hover{opacity:1}
.client-modal-box{background:var(--bg-card);border-radius:var(--radius);padding:22px;width:100%;max-width:440px;box-shadow:var(--shadow-md)}
/* Full-window drag & drop overlay */
.media-drop-overlay{position:fixed;inset:0;z-index:9998;display:none;align-items:center;justify-content:center;background:rgba(79,70,229,.10);backdrop-filter:blur(2px);border:4px dashed var(--primary);pointer-events:none}
.media-drop-overlay.active{display:flex;animation:mediaDropIn .12s ease-out}
@keyframes mediaDropIn{from{opacity:0}to{opacity:1}}
.media-drop-inner{background:var(--bg-card);border-radius:var(--radius);padding:34px 52px;box-shadow:var(--shadow-md);text-align:center;pointer-events:none}
.media-drop-icon{font-size:3rem;margin-bottom:10px;animation:mediaDropBounce 1s ease-in-out infinite}
@keyframes mediaDropBounce{0%,100%{transform:translateY(0)}50%{transform:translateY(-6px)}}
.media-drop-text{font-size:1.15rem;font-weight:700;color:var(--primary)}
.media-drop-sub{margin-top:8px;font-size:.9rem;color:var(--text-secondary)}

/* ===== Contract editor ===== */
.section-block{transition:border-color .15s ease, box-shadow .15s ease}
.section-block:hover{border-color:var(--primary) !important;box-shadow:0 1px 6px rgba(0,0,0,.05)}
.section-block .sec-num{display:inline-flex;min-width:22px;height:22px;align-items:center;justify-content:center;background:var(--primary-light);color:var(--primary);border-radius:6px;font-weight:700}
.section-block textarea{resize:vertical;min-height:120px;overflow:hidden;line-height:1.55}
#sections-list{counter-reset:none}

/* ===== Dashboard Expected Income ===== */
.stats-grid-expected{margin-top:-4px;margin-bottom:16px;grid-template-columns:repeat(3,1fr)}
.stat-card-expected{border:2px dashed var(--border);background:transparent;box-shadow:none}
.stat-card-expected .stat-value{font-size:1.1rem}
.stat-card-expected .stat-label{color:var(--text-muted);font-size:.75rem}
@media(max-width:600px){.stats-grid-expected{grid-template-columns:1fr}}

/* ===== Dashboard 2.0: Emergency Strip ===== */
.emergency-strip{display:flex;align-items:center;gap:8px;padding:10px 16px;background:var(--danger-light);border:1px solid var(--danger);border-radius:var(--radius);margin-bottom:14px;font-size:.85rem;color:var(--danger);flex-wrap:wrap}
.emergency-icon{font-size:1.1rem}
.emergency-text{flex:1}
.emergency-link{color:var(--danger);font-weight:600;text-decoration:underline}
.emergency-link:hover{color:var(--text)}
.emergency-sep{margin:0 4px;opacity:.5}
.emergency-action{font-weight:600;color:var(--danger);white-space:nowrap;text-decoration:none}
.emergency-action:hover{text-decoration:underline}

/* ===== Dashboard 2.0: Expected Line ===== */
.dashboard-expected-line{text-align:left;margin-top:8px;margin-bottom:6px}
.dashboard-expected-line a{color:var(--text-muted);font-size:.82rem;transition:color .2s;text-decoration:none}
.dashboard-expected-line a:hover{color:var(--primary);text-decoration:underline}

/* ===== Dashboard 2.0: Day Focus ===== */
.day-focus{display:grid;grid-template-columns:1fr 1fr 1fr;gap:12px;margin-bottom:16px}
.day-focus-col{background:var(--bg-card);border-radius:var(--radius);box-shadow:var(--shadow);padding:12px;min-height:120px}
.day-focus-header{display:flex;justify-content:space-between;align-items:center;font-weight:600;font-size:.85rem;margin-bottom:10px;padding-bottom:8px;border-bottom:2px solid var(--border)}
.day-focus-header-danger{border-bottom-color:var(--danger);color:var(--danger)}
.day-focus-header-warning{border-bottom-color:var(--warning);color:var(--warning)}
.day-focus-header-info{border-bottom-color:var(--info);color:var(--info)}
.day-focus-counter{font-size:.75rem;font-weight:500;color:var(--text-secondary)}
.day-focus-empty{text-align:center;padding:20px 10px;color:var(--text-muted);font-size:.85rem}
.day-focus-empty-success{color:var(--success);font-weight:500}
.day-focus-col .list-item{padding:6px 0}
.day-focus-col .list-item-title{font-size:.85rem}
.day-focus-col .list-item-meta{font-size:.72rem}

/* ===== Dashboard 2.0: Bottom Row ===== */
.dashboard-bottom-row{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px}

/* ===== Dashboard 2.0: Revenue Chart ===== */
#revenue-chart-section{margin-bottom:16px}
#top-clients-section{margin-bottom:16px}

/* ===== Dashboard: Enhanced Task Cards ===== */
.df-task{border-left:3px solid transparent;padding-left:8px !important}
.df-task-overdue{border-left-color:#ef4444}
.df-task-today{border-left-color:#f59e0b}
.df-task-week{border-left-color:#6366f1}

.df-task-row{display:flex;align-items:center;gap:4px;min-width:0}
.df-task-row .list-item-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.df-priority{font-size:.6rem;font-weight:700;padding:1px 5px;border-radius:3px;flex-shrink:0;line-height:1.4}
.df-priority-urgent{background:#ef4444;color:#fff}
.df-priority-high{background:#f59e0b;color:#fff}

.df-desc-hint{font-size:.7rem;opacity:.5;cursor:help;flex-shrink:0}

.df-price{font-size:.7rem;font-weight:600;color:var(--success);background:var(--success-light);padding:1px 6px;border-radius:10px;flex-shrink:0;white-space:nowrap}

.df-due-today{color:#f59e0b;font-weight:600}
.df-due-week{color:var(--text-secondary)}

.df-complete-btn{width:32px;height:32px;border-radius:50%;background:var(--success-light);color:var(--success);border:2px solid var(--success);display:flex;align-items:center;justify-content:center;font-size:.85rem;cursor:pointer;transition:all .15s;flex-shrink:0;padding:0;line-height:1}
.df-complete-btn:hover{background:var(--success);color:#fff}

/* ===== Dashboard: Top Clients Layout ===== */
.top-clients-layout{display:flex;gap:16px;align-items:flex-start}
.top-clients-list{flex:1;min-width:0}
.top-clients-donut{flex-shrink:0}
.top-clients-donut-wrap{position:relative;width:160px;height:160px;display:flex;align-items:center;justify-content:center}
.top-clients-donut-center{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center;display:flex;flex-direction:column;line-height:1.3}

.top-client-row{padding:6px 0;border-bottom:1px solid var(--border)}
.top-client-row:last-child{border-bottom:none}
.top-client-bar{height:3px;background:var(--border);border-radius:2px;margin-top:4px;overflow:hidden}
.top-client-bar-fill{height:100%;background:#6366f1;border-radius:2px;transition:width .3s ease}

/* ===== Dashboard 2.0: Responsive ===== */
@media(max-width:768px){
    .day-focus{grid-template-columns:1fr}
    .dashboard-bottom-row{grid-template-columns:1fr}
    .top-clients-layout{flex-direction:column}
    .top-clients-donut{align-self:center}
}

/* ===== Profile Dropdown ===== */
.profile-dropdown-wrap{position:relative}
.profile-dropdown-toggle{cursor:pointer;border:none}
.user-avatar-img{width:32px;height:32px;border-radius:50%;object-fit:cover}
.profile-dropdown{position:absolute;top:calc(100% + 8px);right:0;min-width:220px;background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-md);z-index:250;animation:fadeIn .15s ease}
.profile-dropdown-header{padding:12px 16px;display:flex;flex-direction:column;gap:2px}
.profile-dropdown-header strong{font-size:.85rem}
.profile-dropdown-header .text-muted{color:var(--text-muted);font-size:.75rem}
.profile-dropdown-divider{height:1px;background:var(--border)}
.profile-dropdown-item{display:flex;align-items:center;gap:10px;padding:10px 16px;color:var(--text);text-decoration:none;font-size:.85rem;transition:background .15s}
.profile-dropdown-item:hover{background:var(--bg);text-decoration:none}
.profile-dropdown-item svg{flex-shrink:0;color:var(--text-secondary)}
.profile-dropdown-danger{color:var(--danger)}
.profile-dropdown-danger svg{color:var(--danger)}

/* ===== Avatar Upload ===== */
.avatar-upload-wrap{display:flex;align-items:center;gap:16px;flex-wrap:wrap}
.avatar-preview{width:80px;height:80px;border-radius:50%;background:var(--primary);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:2rem;overflow:hidden;flex-shrink:0}
.avatar-preview img{width:100%;height:100%;object-fit:cover}
.avatar-form{display:flex;align-items:center;gap:8px}
.avatar-upload-btn{cursor:pointer}

/* ===== Crop Modal ===== */
.crop-modal{position:fixed;top:0;left:0;right:0;bottom:0;z-index:9999;display:flex;align-items:center;justify-content:center;padding:16px}
.crop-modal.hidden{display:none}
.crop-modal-backdrop{position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.7)}
.crop-modal-content{position:relative;background:var(--bg-card);border-radius:var(--radius-lg,12px);box-shadow:var(--shadow-md);width:100%;max-width:500px;max-height:90vh;display:flex;flex-direction:column;overflow:hidden}
.crop-modal-header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid var(--border)}
.crop-modal-title{font-weight:600;font-size:.95rem;color:var(--text)}
.crop-modal-close{background:none;border:none;font-size:1.5rem;cursor:pointer;color:var(--text-secondary);padding:0 4px;line-height:1}
.crop-modal-close:hover{color:var(--text)}
.crop-modal-body{padding:16px;overflow:auto;flex:1}
.crop-container{max-height:60vh;overflow:hidden}
.crop-container img{max-width:100%;display:block}
.crop-modal-footer{display:flex;justify-content:flex-end;gap:8px;padding:12px 16px;border-top:1px solid var(--border)}
@media(max-width:500px){.crop-modal-content{max-width:100%;border-radius:var(--radius,8px)}}

/* ===== Toast ===== */
.toast{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:var(--text);color:var(--bg-card);padding:10px 20px;border-radius:var(--radius,8px);font-size:.85rem;z-index:10000;opacity:0;transition:opacity .3s;pointer-events:none}
.toast.visible{opacity:1}

/* ===== Toggle Labels ===== */
.toggle-label{display:flex;align-items:center;gap:8px;cursor:pointer;font-size:.9rem}
.toggle-label input[type="checkbox"]{width:18px;height:18px;accent-color:var(--primary);cursor:pointer}

/* ===== Utility ===== */
.text-xs{font-size:.75rem}
.text-sm{font-size:.85rem}
.mt-05{margin-top:4px}

@media(max-width:767px){
    .profile-dropdown{right:-8px;min-width:200px}
}

/* ===== Colored Tags ===== */
.tag-colored{display:inline-block;padding:2px 8px;border-radius:12px;font-size:.7rem;font-weight:600;color:#fff;margin:2px}

/* ===== Mini Revenue Chart ===== */
.mini-chart{display:flex;align-items:flex-end;gap:3px;height:32px}
.mini-bar{width:16px;border-radius:2px 2px 0 0;background:var(--primary);min-height:2px;transition:height .3s}
.mini-bar-label{font-size:.6rem;text-align:center;color:var(--text-muted);margin-top:2px}
.mini-chart-wrap{display:flex;flex-direction:column;align-items:center;gap:2px}

/* ===== Client Header Stats ===== */
.client-header-stats{display:flex;gap:16px;flex-wrap:wrap;align-items:center;margin-top:8px;font-size:.8rem;color:var(--text-secondary)}
.client-header-stats .stat-item{display:flex;align-items:center;gap:4px}
.next-contact-badge{padding:2px 8px;border-radius:var(--radius-sm);font-size:.75rem;font-weight:500}
.next-contact-badge.overdue{background:var(--danger-light);color:var(--danger)}
.next-contact-badge.upcoming{background:var(--info-light);color:var(--info)}

/* ===== Summary Stats Grid ===== */
.summary-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px}
.summary-stat{background:var(--bg);border-radius:var(--radius);padding:16px;text-align:center}
.summary-stat-value{font-size:1.2rem;font-weight:700;color:var(--text)}
.summary-stat-label{font-size:.75rem;color:var(--text-secondary);margin-top:4px}

/* ===== Structured Notes ===== */
.note-entry{padding:12px;border-left:3px solid var(--border);margin-bottom:8px;background:var(--bg-card);border-radius:0 var(--radius-sm) var(--radius-sm) 0}
.note-entry-header{display:flex;align-items:center;gap:8px;margin-bottom:6px;font-size:.75rem;color:var(--text-secondary)}
.note-type-badge{padding:2px 8px;border-radius:10px;font-size:.7rem;font-weight:600;color:#fff}
.note-type-general{background:#6b7280}
.note-type-call{background:#10b981}
.note-type-meeting{background:#8b5cf6}
.note-type-email{background:#3b82f6}
.note-entry-content{font-size:.85rem;white-space:pre-wrap}
.note-entry-actions{float:right}

/* ===== Follow-up Badge ===== */
.followup-item{display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border)}
.followup-item:last-child{border-bottom:none}
.followup-overdue{color:var(--danger);font-size:.75rem;font-weight:500}

/* ===== Tag Filter Bar ===== */
.tag-filter-bar{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:12px}
.tag-filter-bar .tag-colored{cursor:pointer;opacity:.7;transition:opacity .2s}
.tag-filter-bar .tag-colored:hover,.tag-filter-bar .tag-colored.active{opacity:1;box-shadow:0 0 0 2px var(--primary)}

/* ===== Invoice Compact List ===== */
.inv-list{display:flex;flex-direction:column;gap:4px}
.inv-row{display:flex;align-items:center;gap:10px;padding:8px 14px;background:var(--bg-card);border-radius:var(--radius);box-shadow:var(--shadow)}
.inv-row .bulk-check{flex-shrink:0}
.inv-main{flex:1;min-width:0;display:flex;align-items:baseline;gap:0;flex-wrap:wrap}
.inv-title{font-weight:600;font-size:.88rem;color:var(--text);text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:280px;display:inline-block}
.inv-title:hover{color:var(--primary)}
.inv-sep{color:var(--text-muted);margin:0 5px;font-size:.78rem}
.inv-client{font-size:.78rem;color:var(--text-muted);text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:200px;display:inline-block;vertical-align:baseline}
.inv-client:hover{color:var(--primary)}
.inv-meta{display:flex;gap:8px;flex-shrink:0;font-size:.75rem;color:var(--text-muted)}
.inv-meta-due{opacity:.7}
.inv-amount{font-weight:700;font-size:.88rem;white-space:nowrap;flex-shrink:0;min-width:80px;text-align:right}
.inv-actions{display:flex;gap:4px;align-items:center;flex-shrink:0}
.inv-actions .btn-xs{padding:3px 8px;font-size:.75rem}
.inv-action-hover{opacity:0;transition:opacity .15s}
.inv-row:hover .inv-action-hover{opacity:1}
.inv-row .badge{font-size:.68rem;padding:2px 7px;border-radius:4px;flex-shrink:0}

/* Invoice status color strip */
.invoice-card-planned{border-left:4px solid var(--text-muted)}
.invoice-card-sent{border-left:4px solid var(--info)}
.invoice-card-paid{border-left:4px solid var(--success)}
.invoice-card-canceled{border-left:4px solid var(--danger)}
.invoice-card-overdue{border-left:4px solid var(--danger)}

/* Invoice view toggle */
.inv-view-btn{min-width:30px;text-align:center;font-size:1rem;line-height:1;padding:3px 6px}
.inv-view-btn.active{background:var(--primary);color:#fff;border-color:var(--primary)}

/* Invoice table */
.inv-table{width:100%;border-collapse:collapse;font-size:.85rem}
.inv-table thead{position:sticky;top:0;z-index:2}
.inv-table th{background:var(--bg-card);padding:8px 10px;text-align:left;font-weight:600;font-size:.75rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.03em;border-bottom:2px solid var(--border)}
.inv-table td{padding:6px 10px;border-bottom:1px solid var(--border);vertical-align:middle}
.inv-table tbody tr{height:40px;transition:background .1s}
.inv-table tbody tr:nth-child(even){background:rgba(127,127,127,.04)}
.inv-table tbody tr:hover{background:var(--primary-light, rgba(99,102,241,.08))}
.inv-tbl-row{border-left:4px solid transparent}
.inv-tbl-row.invoice-card-planned{border-left-color:var(--text-muted)}
.inv-tbl-row.invoice-card-sent{border-left-color:var(--info)}
.inv-tbl-row.invoice-card-paid{border-left-color:var(--success)}
.inv-tbl-row.invoice-card-canceled{border-left-color:var(--danger)}
.inv-tbl-row.invoice-card-overdue{border-left-color:var(--danger)}
.inv-table .inv-title{font-weight:600;font-size:.85rem}
.inv-table .inv-client{font-size:.8rem;color:var(--text-muted)}

/* ===== Invoice Filter Form ===== */
.invoice-filter-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: flex-end;
}
.invoice-filter-form .form-group:first-of-type {
    grid-column: 1 / -1;
}
.invoice-filter-form .filter-btn-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.invoice-filter-form .filter-btn-wrap .btn {
    width: 100%;
    min-height: 38px;
}
@media (min-width: 768px) {
    .invoice-filter-form {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .invoice-filter-form .form-group:first-of-type {
        flex: 2 1 200px;
    }
    .invoice-filter-form .form-group {
        flex: 1 0 120px;
    }
    .invoice-filter-form .filter-btn-wrap {
        flex: 0 0 auto;
    }
    .invoice-filter-form .filter-btn-wrap .btn {
        width: auto;
    }
}

/* ===== Invoice List Mobile ===== */
@media (max-width: 767px) {
    .inv-row{flex-wrap:wrap;padding:8px 10px;gap:6px}
    .inv-main{flex:1 1 100%;order:1}
    .inv-title{max-width:60vw}
    .inv-client{max-width:45vw}
    .inv-meta{order:3;flex:1 1 100%;gap:6px}
    .inv-amount{order:2;margin-left:auto}
    .inv-actions{order:4;flex:1 1 100%}
    .inv-action-hover{opacity:1}
}

/* ===== Invoice Summary Stats ===== */
.invoice-summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:6px;margin-bottom:8px;padding:10px 14px;background:var(--bg-card);border-radius:var(--radius);box-shadow:var(--shadow)}
.invoice-summary-item{text-align:center}
.invoice-summary-value{font-size:1.1rem;font-weight:700;color:var(--text)}
.invoice-summary-label{font-size:.72rem;color:var(--text-secondary);margin-top:2px}
.btn-invoice-remind{width:32px;height:32px;border-radius:50%;border:2px solid var(--success);background:transparent;color:var(--success);font-size:14px;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.btn-invoice-remind:hover{background:var(--success);color:#fff}

/* ===== Transaction Categories ===== */
.badge-category{background:var(--info-bg, #dbeafe);color:var(--info, #3b82f6);font-size:.7rem;padding:2px 8px;border-radius:10px;font-weight:500}

/* Category breakdown in transactions list */
.cat-breakdown-list{display:flex;flex-direction:column;gap:6px}
.cat-breakdown-row{display:flex;flex-direction:column;gap:2px}
.cat-breakdown-bar{height:4px;background:var(--border);border-radius:2px;overflow:hidden}
.cat-breakdown-fill{height:100%;background:var(--primary);border-radius:2px;transition:width .3s}

/* ===== Report Chart Legend ===== */
.chart-legend{display:flex;flex-direction:column;gap:6px}
.chart-legend-item{display:flex;align-items:center;gap:8px;font-size:.85rem}
.chart-legend-dot{width:10px;height:10px;border-radius:50%;flex-shrink:0}

/* ===== Notification Bell ===== */
.notif-bell{position:relative;background:none;border:none;color:var(--text-secondary);cursor:pointer;padding:6px;border-radius:50%;transition:all .15s;display:flex;align-items:center;justify-content:center}
.notif-bell:hover{color:var(--text);background:var(--bg-hover)}
.notif-bell.notif-active{color:var(--success)}
.notif-bell.notif-active::after{content:'';width:6px;height:6px;border-radius:50%;background:var(--success);position:absolute;top:4px;right:4px}

/* ===== Dashboard Widget Customization ===== */
.widget { position: relative; transition: opacity 0.2s; margin-bottom: 12px; }
.widget-header {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    gap: 4px;
    z-index: 10;
}
.drag-handle {
    cursor: grab;
    font-size: 1.1rem;
    color: var(--text-muted);
    padding: 2px 4px;
    background: var(--bg-card);
    border-radius: 4px;
    border: 1px solid var(--border);
    line-height: 1;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }
.widget-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    line-height: 1.4;
}
.widget-toggle:hover { background: var(--bg); }
.widget.dragging { opacity: 0.4 !important; }
.widget-collapsed > *:not(.widget-header) { display: none; }
.widget-collapsed { opacity: 0.35; min-height: 36px; border: 2px dashed var(--border); border-radius: var(--radius); padding: 4px; }

/* Edit mode — block text selection while dragging */
#dashboard-widgets.edit-mode,
#dashboard-widgets.edit-mode * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    user-select: none !important;
}

/* Dashboard edit hint — sticky bar */
#dashboard-edit-hint {
    position: sticky;
    top: 60px;
    z-index: 50;
    background: var(--info-light, #e8f4fd);
    border: 1px solid var(--info, #3b82f6);
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: .82rem;
    color: var(--info, #3b82f6);
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
#dashboard-edit-hint .hint-text { flex: 1; min-width: 160px; }
#dashboard-edit-hint .hint-actions { display: flex; gap: 6px; }
.hint-text-mobile { display: none; }

/* Dashboard edit button — desktop/mobile text toggle */
.btn-text-mobile { display: none; }
.btn-text-desktop { display: inline; }

@media (max-width: 767px) {
    .btn-text-mobile { display: inline; }
    .btn-text-desktop { display: none; }
    #dashboard-edit-btn {
        padding: 0 !important;
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        max-width: 36px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        line-height: 1;
        flex-shrink: 0;
    }
    .hint-text-desktop { display: none; }
    .hint-text-mobile { display: inline; }
    #dashboard-edit-hint {
        flex-wrap: wrap;
        gap: 8px;
        font-size: .78rem;
    }
    #dashboard-edit-hint .btn {
        flex: 1;
        min-height: 44px;
        justify-content: center;
    }
    /* Mobile drag handle — full-width bar above widget */
    .edit-mode .drag-handle {
        display: block;
        width: 100%;
        text-align: center;
        padding: 8px;
        margin-bottom: 4px;
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
        background: var(--primary-light);
        color: var(--primary);
        font-size: 1.2rem;
        min-height: 36px;
        letter-spacing: 4px;
    }
    .edit-mode .widget-header {
        position: relative;
        top: auto;
        right: auto;
        flex-direction: column;
    }
}

/* Task share button — hidden until hover on desktop */
@media (min-width: 768px) {
    .list-item .task-share-btn { opacity: 0; transition: opacity 0.15s; }
    .list-item:hover .task-share-btn { opacity: 1; }
}
@media (max-width: 767px) {
    .list-item .task-share-btn { min-width: 36px; min-height: 36px; }
}

/* Media picker modal grid */
.media-picker-item { cursor: pointer; transition: outline 0.15s; border-radius: var(--radius); }
.media-picker-item:hover { outline: 2px solid var(--primary); }
.ql-media-library { font-size: 1rem !important; line-height: 1 !important; }

/* ===== Task Quick Preview Side Panel ===== */
.task-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(0,0,0,0.3);
}
.task-side-panel {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    right: 0;
    width: 400px;
    bottom: 0;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
    animation: slideInRight 0.2s ease;
}
.task-side-panel-inner { padding: 20px; }
.task-preview-desc { word-break: break-word; }
.task-preview-desc img { max-width: 100%; border-radius: var(--radius); }

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@media (max-width: 767px) {
    .task-side-panel { display: none; }
    .task-preview-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        max-height: 80vh;
        overflow-y: auto;
        animation: slideUp 0.2s ease;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    }
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ===== Sticky Form Footer ===== */
.form-sticky-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    padding: 12px 0;
    border-top: 1px solid var(--border);
    margin-top: 16px;
    display: flex;
    gap: 8px;
    z-index: 10;
}
@media (max-width: 767px) {
    .form-sticky-footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
}

/* ===== Title Character Counter ===== */
.title-counter {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.72rem;
    color: var(--text-muted);
    pointer-events: none;
}

/* ===== Invoice Overflow Menu ===== */
.invoice-overflow-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 50;
    overflow: hidden;
}
.invoice-overflow-item {
    display: block;
    width: 100%;
    padding: 8px 14px;
    font-size: 0.82rem;
    color: var(--text);
    text-align: left;
    border: none;
    background: none;
    cursor: pointer;
    text-decoration: none;
}
.invoice-overflow-item:hover {
    background: var(--bg);
    text-decoration: none;
}

/* Transaction delete button — hidden until hover on desktop */
@media (min-width: 768px) {
    .tx-delete-btn { opacity: 0; transition: opacity 0.15s; }
    .list-item:hover .tx-delete-btn { opacity: 1; }
}

/* ===== Voice Input & AI Buttons ===== */
.voice-input-wrap {
    position: relative;
}
.voice-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    padding: 0;
}
.voice-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.voice-btn-recording {
    color: #fff !important;
    background: var(--danger) !important;
    border-color: var(--danger) !important;
    animation: voice-pulse 1s infinite;
}
.voice-btn-recording svg { stroke: #fff; }
.voice-btn-loading {
    opacity: 0.5;
    pointer-events: none;
    animation: voice-spin 1s linear infinite;
}
@keyframes voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}
@keyframes voice-spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}
/* Recording overlay for input fields */
.voice-input-wrap .voice-recording-indicator {
    position: absolute;
    left: 0; right: 40px; top: 0; bottom: 0;
    background: rgba(239, 68, 68, 0.08);
    border: 2px solid var(--danger);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    padding-left: 12px;
    gap: 6px;
    z-index: 2;
    pointer-events: none;
}
.voice-recording-indicator .rec-dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
    animation: rec-blink 1s infinite;
}
.voice-recording-indicator .rec-text {
    font-size: .8rem; color: var(--danger); font-weight: 600;
}
.voice-recording-indicator .rec-waves {
    display: flex; align-items: center; gap: 2px; margin-left: auto; margin-right: 12px;
}
.voice-recording-indicator .rec-waves span {
    display: inline-block; width: 3px; background: var(--danger); border-radius: 2px;
    animation: rec-wave 0.6s ease-in-out infinite alternate;
}
.voice-recording-indicator .rec-waves span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-recording-indicator .rec-waves span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.voice-recording-indicator .rec-waves span:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.voice-recording-indicator .rec-waves span:nth-child(4) { height: 16px; animation-delay: 0.3s; }
.voice-recording-indicator .rec-waves span:nth-child(5) { height: 8px; animation-delay: 0.4s; }
@keyframes rec-blink { 0%,100%{opacity:1} 50%{opacity:.3} }
@keyframes rec-wave { 0%{height:4px} 100%{height:18px} }
/* Quill toolbar recording state */
#quill-toolbar.quill-recording { border-color: var(--danger); background: rgba(239,68,68,0.06); }

/* Voice btn inside Quill toolbar */
.voice-btn-toolbar {
    position: static;
    transform: none;
    display: inline-flex;
    vertical-align: middle;
    margin-left: 4px;
    width: 26px;
    height: 26px;
}

/* AI Improve button in toolbar */
.ai-improve-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 4px;
    height: 26px;
    transition: all 0.2s;
}
.ai-improve-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.ai-improve-loading {
    opacity: 0.5;
    pointer-events: none;
}
.ai-improve-loading::after {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 4px;
}

/* ===== Notification Bell Link + Badge ===== */
.notif-bell-link {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
}
.notif-bell-link:hover {
    background: var(--bg-hover);
}
.notif-count-badge {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

/* ===== Notifications Page ===== */
.notif-page-badge {
    display: inline-block;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    margin-left: 6px;
}

.notif-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.notif-item {
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.notif-item:last-child {
    border-bottom: none;
}

.notif-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    position: relative;
    z-index: 1;
    transition: transform 0.25s ease;
}

.notif-unread .notif-content {
    background: var(--bg-hover, rgba(79, 70, 229, 0.04));
}

.notif-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.notif-body {
    flex: 1;
    min-width: 0;
}

.notif-title {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.3;
    color: var(--text);
}
.notif-read .notif-title {
    font-weight: 400;
    color: var(--text-muted);
}

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

.notif-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.notif-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 6px;
}

/* Swipe action backgrounds */
.notif-swipe-action {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    opacity: 0;
    transition: opacity 0.15s;
}
.notif-swipe-right {
    left: 0;
    padding-left: 20px;
    background: var(--success, #22c55e);
    justify-content: flex-start;
}
.notif-swipe-left {
    right: 0;
    padding-right: 20px;
    background: var(--warning, #f59e0b);
    justify-content: flex-end;
}
.notif-show-right .notif-swipe-right {
    opacity: 1;
}
.notif-show-left .notif-swipe-left {
    opacity: 1;
}

/* ===== AI Usage Stats (profile) ===== */
.ai-usage-stats {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: var(--radius, 8px);
    border: 1px solid var(--border-color, #e2e8f0);
}
.ai-usage-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.ai-stats-loading {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* AI Settings Page */
.ai-provider-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:var(--spacing-sm)}
.ai-provider-card{display:flex;flex-direction:column;align-items:center;gap:4px;padding:var(--spacing-md);border:2px solid var(--border);border-radius:var(--radius);cursor:pointer;transition:all .2s;text-align:center}
.ai-provider-card:hover{border-color:var(--text-muted)}
.ai-provider-card.active{border-color:var(--primary);background:rgba(99,102,241,.06)}
.ai-provider-card input[type=radio]{display:none}
.ai-stats-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:var(--spacing-sm)}
.ai-stat-card{background:var(--bg-input);padding:var(--spacing-sm);border-radius:var(--radius);text-align:center}
.ai-stat-value{font-size:1.1rem;font-weight:700;color:var(--text)}
.ai-stat-label{font-size:.75rem;color:var(--text-muted)}
.ai-usage-months{display:grid;grid-template-columns:1fr 1fr;gap:var(--spacing-md)}
.ai-usage-month h4{font-size:.9rem;margin:0 0 var(--spacing-xs)}
.ai-prompt-examples{display:flex;flex-wrap:wrap;gap:6px;margin-top:var(--spacing-xs)}
.ai-prompt-example{padding:4px 10px;border:1px solid var(--border);border-radius:var(--radius);cursor:pointer;transition:all .15s}
.ai-prompt-example:hover{border-color:var(--primary);background:rgba(99,102,241,.06)}
.ai-search-toggle{padding:4px 0 0;display:flex;align-items:center;gap:4px}
.ai-search-toggle label{font-size:.7rem;color:var(--text-muted);cursor:pointer;display:flex;align-items:center;gap:4px}
.ai-search-result mark{background:rgba(245,158,11,.3);border-radius:2px;padding:0 2px}
.ai-msg-cost{font-size:.65rem;color:var(--text-muted);margin-top:6px;opacity:.7;text-align:right}
@media(max-width:768px){
    .ai-stats-grid{grid-template-columns:repeat(2,1fr)}
    .ai-usage-months{grid-template-columns:1fr}
    .ai-provider-grid{grid-template-columns:1fr}
}

.spinner-sm {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.ai-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.ai-stats-month {
    padding: 0.5rem;
    background: var(--bg-primary, #fff);
    border-radius: var(--radius, 8px);
    border: 1px solid var(--border-color, #e2e8f0);
}
.ai-stats-month-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-color);
}
.ai-stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.15rem 0;
    font-size: 0.72rem;
}
.ai-stats-label {
    color: var(--text-muted);
}
.ai-stats-value {
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.ai-stats-cost {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.25rem;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border-color);
    text-align: right;
}
.ai-stats-models {
    margin-top: 0.35rem;
    padding-top: 0.25rem;
    border-top: 1px dashed var(--border-color);
}
.ai-stats-model-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 0.1rem 0;
}
.ai-stats-model-name {
    font-family: monospace;
    opacity: 0.8;
}
.ai-stats-no-data {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem;
}
@media (max-width: 480px) {
    .ai-stats-grid { grid-template-columns: 1fr; }
}

/* ===== AI Assistant Chat ===== */

/* FAB Group — two buttons stacked */
.ai-fab-group {
    position: fixed;
    bottom: 80px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 95;
    align-items: center;
}
.ai-fab {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(99,102,241,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.ai-fab:hover { transform: scale(1.08); box-shadow: 0 6px 16px rgba(99,102,241,0.5); }
.ai-fab:active { transform: scale(0.95); }
.ai-fab.recording {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 12px rgba(239,68,68,0.5);
    animation: ai-pulse 1.2s ease-in-out infinite;
}
@keyframes ai-pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(239,68,68,0.4); }
    50% { box-shadow: 0 4px 24px rgba(239,68,68,0.7); }
}

/* Resize handle (left edge of drawer, desktop only) */
.ai-chat-resize-handle {
    display: none;
}
@media (min-width: 769px) {
    .ai-chat-resize-handle {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 6px;
        height: 100%;
        cursor: ew-resize;
        z-index: 10;
        background: transparent;
        transition: background 0.15s;
    }
    .ai-chat-resize-handle:hover,
    .ai-chat-resize-handle:active {
        background: var(--primary, #6366f1);
        opacity: 0.3;
    }
}

/* Chat overlay + drawer */
.ai-chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: opacity 0.2s;
}
.ai-chat-overlay.hidden { display: none; }

.ai-chat-drawer {
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--bg-card);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    animation: ai-slide-up 0.25s ease-out;
    position: relative;
}
@keyframes ai-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ai-chat-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}
.ai-chat-header-actions { display: flex; gap: 4px; }
.ai-chat-header-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
}
.ai-chat-header-btn:hover { background: var(--bg); color: var(--text); }

/* Messages area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: 55vh;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.ai-msg {
    display: flex;
    max-width: 88%;
}
.ai-msg-user { align-self: flex-end; }
.ai-msg-assistant { align-self: flex-start; }

.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}
.ai-msg-user .ai-msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-msg-bubble {
    background: var(--bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
body.dark-theme .ai-msg-assistant .ai-msg-bubble {
    background: var(--bg-input);
}

/* ── Markdown inside assistant bubbles ── */
.ai-msg-assistant .ai-msg-bubble p {
    margin: 0 0 0.4em 0;
}
.ai-msg-assistant .ai-msg-bubble p:last-of-type {
    margin-bottom: 0;
}
.ai-msg-assistant .ai-msg-bubble > br:first-child { display: none; }

.ai-msg-error {
    color: var(--danger);
    font-size: 0.82em;
    margin-top: 0.5em;
    opacity: 0.8;
}

.ai-md-h {
    font-size: 1em;
    font-weight: 700;
    margin: 0.7em 0 0.3em 0;
    line-height: 1.3;
}
h2.ai-md-h { font-size: 1.05em; }
h3.ai-md-h { font-size: 1em; }
h4.ai-md-h, h5.ai-md-h, h6.ai-md-h { font-size: 0.95em; }
.ai-msg-bubble .ai-md-h:first-child { margin-top: 0; }

.ai-md-list {
    margin: 0.3em 0;
    padding-left: 1.4em;
}
.ai-md-list li {
    margin: 0.15em 0;
}
.ai-md-list li::marker {
    color: var(--text-muted);
}

.ai-md-bq {
    margin: 0.4em 0;
    padding: 0.3em 0 0.3em 0.8em;
    border-left: 3px solid var(--primary);
    color: var(--text-muted);
}

/* Inline code */
.ai-md-code {
    background: rgba(0,0,0,0.06);
    padding: 0.15em 0.35em;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    font-size: 0.88em;
}
body.dark-theme .ai-md-code {
    background: rgba(255,255,255,0.1);
}

/* Code block */
.ai-code-block {
    margin: 0.4em 0;
    padding: 10px 12px;
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    font-size: 0.85em;
    line-height: 1.5;
    position: relative;
}
.ai-code-block code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}
.ai-code-block[data-lang]::before {
    content: attr(data-lang);
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 0.7em;
    text-transform: uppercase;
    color: #585b70;
    letter-spacing: 0.05em;
}

/* Tables */
/* Inline charts */
.ai-chart-wrap {
    margin: 0.5em 0;
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 10px 6px 6px;
    overflow-x: auto;
}
.ai-chart {
    width: 100%;
    max-width: 400px;
    height: auto;
    display: block;
    margin: 0 auto;
}
.ai-chart-title {
    font-size: 12px;
    font-weight: 600;
    fill: var(--text);
}
.ai-chart-label {
    font-size: 9px;
    fill: var(--text-secondary);
}

.ai-md-table-wrap {
    overflow-x: auto;
    margin: 0.4em 0;
    border-radius: 6px;
}
.ai-md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
}
.ai-md-table th,
.ai-md-table td {
    padding: 5px 10px;
    border: 1px solid var(--border);
    text-align: left;
}
.ai-md-table th {
    background: rgba(0,0,0,0.04);
    font-weight: 600;
}
body.dark-theme .ai-md-table th {
    background: rgba(255,255,255,0.06);
}
.ai-md-table tr:nth-child(even) td {
    background: rgba(0,0,0,0.02);
}
body.dark-theme .ai-md-table tr:nth-child(even) td {
    background: rgba(255,255,255,0.02);
}

/* Horizontal rule */
.ai-msg-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.6em 0;
}

/* Strikethrough */
.ai-msg-bubble del {
    opacity: 0.6;
}

.ai-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}
.ai-msg-user .ai-msg-bubble a { color: #fff; }

/* Typing indicator */
.ai-msg-thinking .ai-msg-bubble {
    color: var(--text-muted);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-thinking-dots {
    display: inline-flex;
    gap: 3px;
}
.ai-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: ai-dot-bounce 1.2s ease-in-out infinite;
}
.ai-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Streaming cursor — JS appends a <span class="ai-cursor"> during streaming */
.ai-cursor {
    color: var(--primary);
    font-weight: bold;
    animation: ai-cursor-blink 0.6s step-end infinite;
}
@keyframes ai-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Input area */
.ai-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-card);
}
.ai-chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg-input);
    color: var(--text);
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
}
.ai-chat-input:focus { border-color: var(--primary); }
.ai-chat-input.ai-transcribed {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.ai-mic-btn,
.ai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.ai-mic-btn {
    background: var(--bg);
    color: var(--text-secondary);
}
.ai-mic-btn:hover { background: var(--border); }
.ai-mic-btn.recording {
    background: var(--danger);
    color: #fff;
    animation: ai-pulse 1.2s ease-in-out infinite;
    position: relative;
}
.ai-mic-btn.recording::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--danger);
    animation: ai-mic-ring 1.5s ease-out infinite;
    pointer-events: none;
}
@keyframes ai-mic-ring {
    0% { transform: scale(0.8); opacity: 0.8; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Recording overlay (replaces input area during recording) */
.ai-recording-overlay {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--danger);
    flex-shrink: 0;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 5;
}
.ai-recording-overlay.active {
    display: flex;
}
.ai-recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--danger);
    font-weight: 600;
    font-size: 14px;
}
.ai-recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: ai-rec-dot 1s ease-in-out infinite;
}
@keyframes ai-rec-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.ai-recording-waves {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    height: 32px;
    justify-content: center;
}
.ai-recording-waves span {
    display: block;
    width: 3px;
    background: var(--danger);
    border-radius: 2px;
    animation: ai-wave 0.8s ease-in-out infinite;
    opacity: 0.7;
}
.ai-recording-waves span:nth-child(1) { height: 8px; animation-delay: 0s; }
.ai-recording-waves span:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.ai-recording-waves span:nth-child(3) { height: 24px; animation-delay: 0.2s; }
.ai-recording-waves span:nth-child(4) { height: 18px; animation-delay: 0.3s; }
.ai-recording-waves span:nth-child(5) { height: 28px; animation-delay: 0.15s; }
.ai-recording-waves span:nth-child(6) { height: 14px; animation-delay: 0.25s; }
.ai-recording-waves span:nth-child(7) { height: 20px; animation-delay: 0.05s; }
.ai-recording-waves span:nth-child(8) { height: 10px; animation-delay: 0.35s; }
@keyframes ai-wave {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}
.ai-recording-timer {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    min-width: 32px;
}
.ai-recording-cancel {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    font-size: 13px;
    border-radius: 6px;
}
.ai-recording-cancel:hover { background: var(--border); }
.ai-recording-stop {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ai-recording-stop:hover { background: #dc2626; }
.ai-send-btn {
    background: var(--primary);
    color: #fff;
}
.ai-send-btn:hover { background: var(--primary-hover); }
.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Attach button */
.ai-attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg);
    color: var(--text-secondary);
    transition: background 0.15s;
}
.ai-attach-btn:hover { background: var(--border); }

/* Image preview strip above input */
/* Multi-image preview strip */
.ai-image-preview {
    padding: 8px 12px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.ai-image-preview.hidden { display: none; }
.ai-image-preview-item {
    position: relative;
    flex-shrink: 0;
}
.ai-image-preview-item img {
    height: 60px;
    width: 60px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    object-fit: cover;
    cursor: pointer;
}
.ai-image-preview-item .ai-img-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: #fff;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

/* File attachment chips */
.ai-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    max-width: 220px;
    flex-shrink: 0;
}
.ai-file-chip-icon { font-size: 16px; flex-shrink: 0; }
.ai-file-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.ai-file-chip-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}
.ai-file-chip-remove:hover { color: var(--danger); }

/* File chips in message bubbles */
.ai-msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
.ai-msg-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Image thumbnails in chat messages */
.ai-msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}
.ai-msg-image {
    max-width: 150px;
    max-height: 120px;
    border-radius: var(--radius-sm);
    display: block;
    cursor: pointer;
    transition: opacity 0.15s;
    object-fit: cover;
}
.ai-msg-image:hover { opacity: 0.85; }

/* Copy button on messages */
.ai-msg-copy {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    padding: 0;
}
.ai-msg-bubble { position: relative; }
.ai-msg-bubble:hover .ai-msg-copy,
.ai-msg-copy:focus { opacity: 1; }
.ai-msg-copy:hover { background: var(--bg-secondary); color: var(--text-primary); }
/* On mobile, always show (no hover) */
@media (max-width: 768px) { .ai-msg-copy { opacity: 0.5; } }

/* ── Message menu button (three dots) ── */
.ai-msg-menu-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    line-height: 1;
}
.ai-msg-bubble:hover .ai-msg-menu-btn,
.ai-msg-menu-btn:focus { opacity: 1; }
.ai-msg-menu-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
@media (max-width: 768px) { .ai-msg-menu-btn { opacity: 0.5; } }

/* Message action buttons (copy, retry) */
.ai-msg-actions {
    display: flex;
    justify-content: flex-end;
    gap: 2px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.15s;
    position: relative;
}
.ai-msg:hover .ai-msg-actions { opacity: 1; }
@media (max-width: 768px) { .ai-msg-actions { opacity: 0.5; } }
.ai-msg-action-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ai-msg-action-btn:hover {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--text-muted);
}
/* Share dropdown menu */
.ai-share-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 4px;
    z-index: 200;
    min-width: 160px;
    animation: fadeInUp 0.12s ease;
}
.ai-share-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text);
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}
.ai-share-menu button:hover {
    background: var(--bg-secondary);
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Retry button */
.ai-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0 8px 52px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ai-retry-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
    border-color: var(--text-muted);
}

/* ── Quick Actions bar ── */
.ai-quick-actions {
    display: flex;
    gap: 6px;
    padding: 8px 16px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    flex-shrink: 0;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    mask-image: linear-gradient(to right, #000 90%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 90%, transparent 100%);
    padding-bottom: 6px;
}
.ai-quick-actions:active { cursor: grabbing; }
.ai-quick-actions::-webkit-scrollbar { height: 4px; }
.ai-quick-actions::-webkit-scrollbar-track { background: transparent; }
.ai-quick-actions::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.ai-quick-actions::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.ai-quick-actions button {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 0.78em;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: inherit;
}
.ai-quick-actions button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ── Context Menu ── */
.ai-context-menu {
    position: fixed;
    z-index: 1100;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    min-width: 160px;
    padding: 4px 0;
    overflow: hidden;
}
.ai-context-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 14px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 0.85em;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.12s;
}
.ai-context-menu button:hover {
    background: var(--bg-secondary);
}
.ai-context-menu button svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

/* ── Confirmation Card ── */
.ai-confirm-card {
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-left: 3px solid var(--primary);
    border-radius: 10px;
    padding: 12px 14px;
    max-width: 340px;
}
.ai-confirm-title {
    font-weight: 600;
    font-size: 0.85em;
    margin-bottom: 8px;
    color: var(--primary);
}
.ai-confirm-list {
    list-style: none;
    padding: 0;
    margin: 0 0 10px 0;
}
.ai-confirm-list li {
    padding: 4px 0;
    font-size: 0.85em;
    color: var(--text-primary);
}
.ai-confirm-btns {
    display: flex;
    gap: 8px;
}
.ai-confirm-yes,
.ai-confirm-no {
    padding: 6px 16px;
    border-radius: 6px;
    border: none;
    font-size: 0.82em;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s;
}
.ai-confirm-yes {
    background: var(--primary);
    color: #fff;
}
.ai-confirm-yes:hover { opacity: 0.88; }
.ai-confirm-no {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.ai-confirm-no:hover { background: var(--border); }
.ai-confirm-decided .ai-confirm-yes,
.ai-confirm-decided .ai-confirm-no {
    opacity: 0.5;
    cursor: default;
}

/* Fullscreen lightbox */
.ai-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.92);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
}
.ai-lightbox.hidden { display: none; }
.ai-lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    cursor: default;
}
.ai-lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
.ai-lightbox-close:hover { background: rgba(255,255,255,0.3); }

/* Actions list in assistant messages */
.ai-actions-list {
    margin-top: 8px;
    padding: 0;
    list-style: none;
}
.ai-actions-list li {
    padding: 4px 0;
    font-size: 13px;
}
.ai-actions-list li a {
    color: var(--primary);
}

/* Desktop: drawer appears from right side */
@media (min-width: 769px) {
    .ai-fab-group {
        bottom: 88px;
        right: 24px;
    }
    .ai-fab {
        width: 52px;
        height: 52px;
    }
    .ai-chat-overlay {
        align-items: stretch;
        justify-content: flex-end;
    }
    .ai-chat-drawer {
        max-width: 400px;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
        animation: ai-slide-left 0.25s ease-out;
        position: relative;
    }
    @keyframes ai-slide-left {
        from { transform: translateX(100%); }
        to { transform: translateX(0); }
    }
    .ai-chat-messages {
        max-height: none;
        flex: 1;
    }
}

/* Mobile: fullscreen chat, FAB above bottom nav */
@media (max-width: 768px) {
    .ai-fab-group {
        bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
        right: 14px;
    }
    .ai-fab {
        width: 50px;
        height: 50px;
    }
    .ai-chat-overlay {
        background: none;
    }
    .ai-chat-drawer {
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        animation: ai-slide-up 0.2s ease-out;
    }
    .ai-chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
    .ai-chat-messages {
        max-height: none;
        flex: 1;
        min-height: 0;
    }
    .ai-chat-input-wrap {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* ── Scroll-to-bottom button ── */
.ai-scroll-bottom {
    position: sticky;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    z-index: 5;
    transition: opacity 0.2s, background 0.15s;
    margin: -36px auto 0;
    flex-shrink: 0;
}
.ai-scroll-bottom:hover {
    background: var(--bg);
    color: var(--text);
}
.ai-scroll-bottom.hidden { display: none; }

/* ── Context menu extras ── */
.ai-ctx-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
.ai-ctx-danger { color: var(--danger, #e53e3e) !important; }
.ai-ctx-danger:hover { background: rgba(229, 62, 62, 0.08) !important; }

/* ── Lightbox error ── */
.ai-lightbox-error {
    color: rgba(255,255,255,0.7);
    font-size: 16px;
    text-align: center;
    padding: 20px;
}

/* ═══════════════════════════════════════════════════════════════════
   AI Full Page (ChatGPT-like layout)
   ═══════════════════════════════════════════════════════════════════ */
/* Override .main constraints when AI page is inside */
.main:has(.ai-page) {
    max-width: none;
    padding: 0;
    overflow: visible;
}
.ai-page {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
    background: var(--bg);
}

/* ── Thread Sidebar ── */
.ai-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ai-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 10px;
    flex-shrink: 0;
}
.ai-sidebar-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.ai-sidebar-search {
    padding: 0 14px 10px;
    flex-shrink: 0;
}
.ai-sidebar-search input {
    font-size: 13px;
}
.ai-thread-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
    -webkit-overflow-scrolling: touch;
}
.ai-thread-item {
    display: flex;
    flex-direction: column;
    padding: 10px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    position: relative;
    transition: background 0.12s;
    margin-bottom: 2px;
}
.ai-thread-item:hover { background: var(--bg); }
.ai-thread-item.active {
    background: var(--primary-light, rgba(99,102,241,0.08));
    border-left: 3px solid var(--primary);
    padding-left: 7px;
}
.ai-thread-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.ai-thread-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}
.ai-thread-actions {
    position: absolute;
    right: 6px;
    top: 8px;
    display: none;
    gap: 2px;
}
.ai-thread-item:hover .ai-thread-actions { display: flex; }
.ai-thread-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
}
.ai-thread-actions button:hover { background: var(--border); color: var(--text); }
.ai-thread-empty { padding: 20px 14px; text-align: center; }
.ai-sidebar-toggle { display: none; }

/* ── Chat Area ── */
.ai-page-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}
.ai-page-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-card);
}
.ai-page-thread-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-page-chat-actions { display: flex; gap: 4px; }
.ai-page-quick-actions {
    display: flex;
    gap: 6px;
    padding: 8px 20px 6px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    flex-shrink: 0;
    background: var(--bg-card);
    -webkit-overflow-scrolling: touch;
    cursor: grab;
    mask-image: linear-gradient(to right, #000 90%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 90%, transparent 100%);
    padding-bottom: 6px;
}
.ai-page-quick-actions:active { cursor: grabbing; }
.ai-page-quick-actions::-webkit-scrollbar { height: 4px; }
.ai-page-quick-actions::-webkit-scrollbar-track { background: transparent; }
.ai-page-quick-actions::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.ai-page-quick-actions::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.ai-page-quick-actions button {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 0.78em;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: inherit;
}
.ai-page-quick-actions button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.ai-page-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    position: relative;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.ai-page-messages::-webkit-scrollbar { width: 5px; }
.ai-page-messages::-webkit-scrollbar-track { background: transparent; }
.ai-page-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.ai-page-messages::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.ai-page-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
    max-width: 840px;
    width: 100%;
    margin: 0 auto;
}
.ai-page-input-wrap .ai-chat-input {
    flex: 1;
    max-height: 120px;
}

/* ── Textarea scrollbar (inside input) ── */
.ai-chat-input {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.ai-chat-input::-webkit-scrollbar { width: 4px; }
.ai-chat-input::-webkit-scrollbar-track { background: transparent; }
.ai-chat-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.ai-chat-input::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Mobile: sidebar as overlay ── */
@media (max-width: 768px) {
    .ai-page {
        position: relative;
        height: calc(100vh - 56px - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px));
        height: calc(100dvh - 56px - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px));
    }
    .ai-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.15);
    }
    .ai-sidebar.open { transform: translateX(0); }
    .ai-sidebar-toggle {
        display: flex;
        position: absolute;
        top: 10px;
        left: 8px;
        z-index: 50;
        background: var(--primary);
        border: none;
        border-radius: var(--radius);
        padding: 8px;
        cursor: pointer;
        color: #fff;
        align-items: center;
        box-shadow: 0 2px 8px rgba(99,102,241,.3);
    }
    .ai-sidebar.open ~ .ai-sidebar-toggle { background: var(--bg-card); color: var(--text-muted); box-shadow: none; border: 1px solid var(--border); }
    .ai-page-chat-header { padding-left: 48px; }
    .ai-page-messages { padding: 16px 12px; }
    .ai-page-input-wrap {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* ── PWA standalone mode adjustments ── */
@media (display-mode: standalone) {
    .ai-fab-group {
        bottom: calc(env(safe-area-inset-bottom, 20px) + 16px);
    }
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}
@media (display-mode: standalone) and (max-width: 768px) {
    .ai-page {
        height: calc(100vh - 56px - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px));
        height: calc(100dvh - 56px - var(--bottom-nav-height) - env(safe-area-inset-bottom, 0px));
    }
}

/* ===== Mobile Section 3 Fixes ===== */

/* Chat bubble width fix on narrow screens */
@media (max-width: 480px) {
    .ai-msg { max-width: 95%; }
    .ai-msg-bubble { min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
}

/* AI FAB overlap fix: add extra padding so content isn't hidden behind FAB */
@media (max-width: 767px) {
    body.has-sidebar .main {
        padding-bottom: calc(var(--bottom-nav-height) + 80px + env(safe-area-inset-bottom, 0px));
    }
}

/* More button active state */
.bottom-nav-item#bottom-nav-more.active {
    color: var(--primary);
}
