/* GrantWrite - Main Stylesheet - FundingRadar Theme */

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

:root {
    /* FundingRadar color palette */
    --has-green: #2e8b57;
    --has-green-hover: #1f6d3f;
    --has-green-light: rgba(46,139,87,0.08);
    --has-dark-green: #112e1a;
    --has-darker-green: #0e2416;
    --has-dark-blue: #173951;

    --primary: var(--has-green);
    --primary-hover: var(--has-green-hover);
    --primary-light: var(--has-green-light);
    --secondary: #64748b;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #c23a3a;
    --bg: #f6fbf6;
    --bg-white: #ffffff;
    --bg-sidebar: var(--has-dark-green);
    --bg-card: #ffffff;
    --text: #0b2a1a;
    --text-muted: #595959;
    --text-light: #8aa89a;
    --border: #e6f0ea;
    --border-focus: var(--has-green);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --bg-main: #f9fafb;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-active: rgba(46, 139, 87, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --font: Inter, system-ui, 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', monospace;
    --topbar-h: 60px;
    --sidebar-w: 240px;
    --ai-panel-w: 360px;
    --cell-number-w: 40px;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
}

[hidden] { display: none !important; }

.screen { display: flex; height: 100vh; }
.screen[hidden] { display: none !important; }

/* === Login Screen === */
#login-screen {
    background: var(--bg);
    justify-content: center;
    align-items: center;
    padding: 24px;
}

/* Centered login box (FundingRadar style) */
.login-box {
    width: 100%;
    max-width: 440px;
    background: var(--bg-card);
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.09);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.login-brand-logo {
    height: 40px;
    width: auto;
}

.login-brand h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

/* Tabs */
.login-tabs {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
    width: 100%;
    margin-bottom: 20px;
}

.login-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.login-tab.active {
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.login-tab:not(.active):hover { color: var(--text); }

/* Panes */
.login-pane { width: 100%; }

.login-pane-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
}

.login-form { display: flex; flex-direction: column; gap: 2px; }

/* Password field with toggle */
.input-with-icon { position: relative; display: flex; align-items: center; }
.input-with-icon input { width: 100%; padding-right: 2.8rem !important; }
.toggle-password {
    position: absolute; right: 0.6rem;
    background: none; border: none; cursor: pointer;
    font-size: 1rem; opacity: 0.5; transition: opacity 0.15s;
    padding: 0.25rem; line-height: 1;
}
.toggle-password:hover { opacity: 0.9; }

/* Alerts */
.alert { padding: 8px 12px; border-radius: var(--radius); font-size: 0.875rem; margin-bottom: 10px; }
.alert[hidden] { display: none; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid rgba(194,58,58,0.2); }
.alert-success { background: var(--has-green-light); color: var(--success); border: 1px solid rgba(46,139,87,0.2); }

/* Required star */
.required { color: var(--danger); margin-left: 2px; }

/* Hints & links */
.login-hint { margin-top: 14px; text-align: center; font-size: 0.85rem; color: var(--text-muted); }

.link-btn {
    background: none; border: none; color: var(--has-green); font-weight: 600;
    cursor: pointer; font-family: var(--font); font-size: inherit;
    padding: 0; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:hover { color: var(--has-green-hover); }

.login-demo-hint { margin-top: 14px; text-align: center; font-size: 0.78rem; color: var(--text-muted); }
.login-demo-hint code {
    background: var(--has-green-light); color: var(--text);
    padding: 2px 6px; border-radius: 4px;
    font-family: var(--font-mono); font-size: 0.78rem;
    border: 1px solid var(--border);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color 0.15s;
    background: var(--bg-white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-check {
    margin-bottom: 1rem;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text);
    cursor: pointer;
}

.check-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

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

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--has-green);
    color: white;
    box-shadow: 0 2px 8px rgba(46,139,87,0.2);
}
.btn-primary:hover {
    background: var(--has-green-hover);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); border-color: var(--secondary); }

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

.btn-analyze {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: white;
    border: none;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-analyze:hover {
    background: linear-gradient(135deg, #6d28d9, #4338ca);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(99,60,235,0.3);
}
.btn-analyze:disabled { opacity: 0.65; transform: none; cursor: wait; }

.btn-full { width: 100%; justify-content: center; }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.25rem;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg); }

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* === Top Bar === */
.topbar {
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    padding: 0 1rem;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 200px;
}

.logo-small {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--has-dark-green);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-small img {
    height: 32px;
    width: auto;
}

.logo-small span { color: var(--has-green); }

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.breadcrumb-item {
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
}
.breadcrumb-item:hover { color: var(--primary); background: var(--primary-light); }
.breadcrumb-sep { color: var(--text-light); }
.breadcrumb-current { color: var(--text); font-weight: 600; cursor: default; }
.breadcrumb-current:hover { background: none; color: var(--text); }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-badge {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === Layout === */
#app-screen {
    flex-direction: column;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-w);
    background: var(--has-dark-green);
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    transition: width 0.2s, transform 0.2s;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
}

.sidebar-nav {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    background: transparent;
    border: none;
    color: #cbd5e1;
    font-size: 0.875rem;
    font-family: var(--font);
    cursor: pointer;
    border-radius: var(--radius);
    text-align: left;
    width: 100%;
    transition: background 0.15s;
}

.sidebar-item:hover { background: rgba(255,255,255,0.1); color: white; }
.sidebar-item.active { background: var(--has-green); color: white; }
.sidebar-icon { font-size: 1rem; }

.project-nav {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0.75rem;
    flex: 1;
    overflow-y: auto;
}

.project-nav-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 0.5rem;
    padding: 0 0.5rem;
}

.section-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.section-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: #cbd5e1;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: var(--radius);
    transition: background 0.15s;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
    font-family: var(--font);
}

.section-link:hover { background: rgba(255,255,255,0.1); color: white; }
.section-link.active { background: rgba(37, 99, 235, 0.5); color: white; }

/* === Main Content === */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.view[hidden] { display: none !important; }

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.view-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

/* === Dashboard Project Grid === */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.project-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--has-green);
    transform: translateY(-1px);
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.project-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.4;
}

.project-card .description {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.project-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.project-card-actions {
    display: flex;
    gap: 0.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
    align-items: center;
}

/* ── Card ⋯ more-menu ── */
.card-more-wrap {
    position: relative;
}

.card-more-menu {
    position: absolute;
    bottom: calc(100% + 0.35rem);
    left: 0;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 170px;
    padding: 0.25rem 0;
}

.card-more-item {
    display: block;
    width: 100%;
    padding: 0.45rem 1rem;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.82rem;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.card-more-item:hover {
    background: var(--bg);
    color: var(--primary);
}

.card-more-item--danger {
    color: var(--danger, #c0392b);
}

.card-more-item--danger:hover {
    background: #fdf0ee;
    color: var(--danger, #c0392b);
}

.card-more-divider {
    margin: 0.25rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

.btn-sm {
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-draft { background: #fef3c7; color: #92400e; }
.badge-submitted { background: #dbeafe; color: #1e40af; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-primary { background: var(--has-green-light); color: var(--has-dark-green); }

/* === Form Card === */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 640px;
}

/* === Upload Zone === */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 1.5rem;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

.link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

.text-small { font-size: 0.8rem; }
.text-muted { color: var(--text-muted); }

.import-preview h3 { margin-bottom: 1rem; }

/* ── Import section preview ─────────────────────────────────────────── */
.import-title-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
}
.import-title-row label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}
.import-sections-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-height: 360px;
    overflow-y: auto;
}
.import-section-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.65rem;
    background: var(--bg-alt);
}
.import-section-item .import-section-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.import-section-item details summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-top: 0.25rem;
    user-select: none;
}
.import-section-item .import-section-content {
    margin-top: 0.4rem;
    font-size: 0.82rem;
    resize: vertical;
}

.import-url-form {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

#ctx-url-bar { margin-top: 0.5rem; }

.import-url-form-hint { margin-top: 0.5rem; }

.section-divider { margin: 1rem 0; border: none; border-top: 1px solid var(--border); }

.ctx-no-docs { padding: 0.5rem 0; }

.import-url-form .form-input {
    flex: 1;
    min-width: 0;
}

/* ── Context-document section in New Project form ─────────────────── */
.context-docs-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 1rem;
    overflow: hidden;
}

.context-docs-toggle {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: var(--bg-alt);
    border-bottom: 1px solid transparent;
    transition: color 0.15s;
}
.context-docs-toggle::-webkit-details-marker { display: none; }
.context-docs-section[open] .context-docs-toggle {
    border-bottom-color: var(--border);
    color: var(--text);
}
.context-docs-toggle:hover { color: var(--text); }

.context-docs-body {
    padding: 0.75rem;
}

/* ── Compact upload zone (used inside context-docs-body) ─────────── */
.upload-zone--compact {
    padding: 1rem;
    font-size: 0.85rem;
    min-height: 70px;
}

.upload-zone--compact .upload-icon { font-size: 1.5rem; }

/* ── Pending / saved context-document lists ─────────────────────── */
.ctx-pending-list,
.ctx-file-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.5rem;
}

.ctx-pending-item,
.ctx-file-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-radius: calc(var(--radius) - 2px);
    background: var(--bg-alt);
    border: 1px solid var(--border);
    font-size: 0.8rem;
}

.ctx-pending-name,
.ctx-file-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.15rem 0.3rem;
    border-radius: 3px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ── Context badge on project cards ─────────────────────────────── */
.ctx-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.72rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    color: var(--text-muted);
}

.project-card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ── Context tab in AI panel ─────────────────────────────────────── */
.ctx-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.ctx-add-bar {
    display: flex;
    gap: 0.4rem;
}

.ctx-url-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.ctx-url-row .form-input {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    padding: 0.35rem 0.6rem;
}

/* ── Unified sources block (New Project form) ───────────────────────────── */
.sources-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    background: var(--bg-alt);
}

.sources-url-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.sources-url-row .form-input {
    flex: 1;
    min-width: 0;
}

.sources-extra-url-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.sources-extra-url-row .form-input {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.source-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.82rem;
}

.source-chip-icon {
    flex-shrink: 0;
    font-size: 0.9rem;
    line-height: 1;
}

.source-chip-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.source-chip-remove {
    flex-shrink: 0;
}

.sources-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
    margin-top: 0.15rem;
}

/* ── Sources badge on editor header Bronnen button ──────────────────────── */
.sources-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2em;
    height: 1.2em;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    background: #7c3aed;
    color: white;
    border-radius: 999px;
    padding: 0 0.3em;
    margin-left: 0.3em;
    vertical-align: middle;
}

/* ── Analyze-with-AI result panel ───────────────────────────────────────── */
.analyze-template-note {
    display: block;
    margin-top: 0.3rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.analyze-result {
    border: 1.5px solid #7c3aed33;
    border-radius: var(--radius);
    background: color-mix(in srgb, #7c3aed 4%, var(--bg));
    padding: 0.85rem 1rem;
    margin-bottom: 0.5rem;
}

.analyze-result-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
}

.analyze-result-badge {
    font-size: 0.82rem;
    font-weight: 600;
    color: #5b21b6;
    white-space: nowrap;
}

.analyze-result-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}

.analyze-sections-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.analyze-sections-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.analyze-section-chip {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    background: var(--bg);
    border: 1px solid color-mix(in srgb, #7c3aed 20%, var(--border));
    border-radius: calc(var(--radius) - 2px);
    padding: 0.4rem 0.6rem;
}

.analyze-section-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.analyze-section-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

.analyze-section-desc {
    font-size: 0.76rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analyze-section-remove {
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 0.1rem;
}

.import-section-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
}

.import-section-item h4 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.import-section-item p {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: pre-wrap;
    max-height: 100px;
    overflow-y: auto;
}

.import-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* === Notebook Editor === */
.editor-header {
    flex-wrap: wrap;
    gap: 0.75rem;
}

.editor-title-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    flex: 1;
}

.editor-title-badges {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.editor-title-row h2 {
    min-width: 100px;
    outline: none;
    border-bottom: 2px solid transparent;
    padding: 0.15rem 0;
    transition: border-color 0.15s;
}

.editor-title-row h2:focus {
    border-bottom-color: var(--primary);
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
}

/* ── Export / Text / Save dropdowns in the editor toolbar ── */
.editor-more-wrap {
    position: relative;
}

.editor-more-menu {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 160px;
    padding: 0.25rem 0;
}

/* Align to right edge for the Save split-button dropdown */
.editor-more-menu--right {
    left: auto;
    right: 0;
}

.editor-more-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.editor-more-item:hover {
    background: var(--bg);
    color: var(--primary);
}

/* ── Split button (Save + Edit project info chevron) ── */
.btn-split-group {
    display: flex;
}

.btn-split-group #btn-save {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-split-toggle {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
    font-size: 0.7rem;
}

.notebook {
    max-width: 900px;
}

/* Section in notebook */
.notebook-section {
    margin-bottom: 2rem;
}

.notebook-section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--has-green);
}

.notebook-section-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.section-actions {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}

/* Cell */
.cell {
    display: flex;
    gap: 0;
    margin-bottom: 0.5rem;
    position: relative;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.15s;
}

.cell:hover {
    border-color: #cbd5e1;
    box-shadow: var(--shadow-sm);
}

.cell.active {
    border-color: var(--has-green);
    box-shadow: 0 0 0 3px var(--has-green-light);
}

.cell-gutter {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: var(--cell-number-w);
    padding: 0.35rem 0;
    background: var(--bg);
    border-right: 1px solid var(--border);
    border-radius: var(--radius) 0 0 var(--radius);
    flex-shrink: 0;
    user-select: none;
    gap: 0.1rem;
}

.drag-handle {
    font-size: 1rem;
    color: var(--text-light);
    cursor: grab;
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    touch-action: none;
}
.cell:hover .drag-handle { opacity: 1; }
.drag-handle:hover        { color: var(--primary); }
.drag-handle:active       { cursor: grabbing; }

/* Drag-and-drop states */
.cell.dragging {
    opacity: 0.4;
    box-shadow: none;
}
.cell.drag-over[data-drag-position="before"] {
    border-top: 2.5px solid var(--primary);
}
.cell.drag-over[data-drag-position="after"] {
    border-bottom: 2.5px solid var(--primary);
}

.cell-number {
    font-size: 0.7rem;
    color: var(--text-light);
    font-family: var(--font-mono);
    font-weight: 600;
}

.cell-type-icon {
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.cell-body {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.cell-content {
    padding: 0.75rem 1rem;
    min-height: 60px;
    outline: none;
    font-size: 0.9rem;
    line-height: 1.7;
    word-wrap: break-word;
}

/* Edit mode: show raw markdown with pre-wrap */
.cell-content[contenteditable="true"] {
    white-space: pre-wrap;
    background: #fafbff;
}

/* Preview mode: normal whitespace for rendered HTML */
.cell-content[contenteditable="false"] {
    white-space: normal;
    cursor: text;
}

.cell-content[contenteditable="false"]:empty::before {
    content: attr(data-placeholder);
    color: var(--text-light);
    pointer-events: none;
}

/* ── Markdown rendered styles ── */
.cell-content p      { margin: 0 0 0.4rem 0; }
.cell-content p:last-child { margin-bottom: 0; }
.cell-content p.md-empty { margin: 0; min-height: 0.6em; }
.cell-content h1     { font-size: 1.4rem; font-weight: 700; margin: 0.6rem 0 0.3rem; }
.cell-content h2     { font-size: 1.2rem; font-weight: 700; margin: 0.5rem 0 0.25rem; color: var(--has-dark-green); }
.cell-content h3     { font-size: 1rem;   font-weight: 700; margin: 0.4rem 0 0.2rem; color: var(--has-dark-green); }
.cell-content ul,
.cell-content ol     { margin: 0.3rem 0 0.3rem 1.4rem; padding: 0; }
.cell-content li     { margin-bottom: 0.15rem; }
.cell-content strong { font-weight: 700; }
.cell-content em     { font-style: italic; }
.cell-content del    { text-decoration: line-through; color: var(--text-muted); }
.cell-content code   { font-family: var(--font-mono); font-size: 0.85em; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 0.05em 0.3em; }

.cell-toolbar {
    display: none;
    padding: 0.35rem 0.5rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

.cell:hover .cell-toolbar,
.cell.active .cell-toolbar {
    display: flex;
}

.cell-toolbar .btn-sm {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.cell-toolbar-sep {
    width: 1px;
    height: 16px;
    background: var(--border);
    margin: 0 0.25rem;
}

/* Budget cell: horizontal scroll on small screens */
.cell-body .budget-table,
.cell-body .budget-editor-wrap {
    max-width: 100%;
}

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

.budget-table th,
.budget-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.budget-table th {
    background: var(--bg);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.budget-table .amount {
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 600;
}

.budget-total {
    font-weight: 700;
    border-top: 2px solid var(--text);
}

/* Budget editor (editable cells) */
.budget-editable tbody tr:hover {
    background: var(--bg);
}

.budget-editable .budget-input {
    border: 1px solid transparent;
    background: transparent;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.85rem;
    width: 100%;
    transition: border-color 0.15s, background 0.15s;
}

.budget-editable .budget-input:hover,
.budget-editable .budget-input:focus {
    border-color: var(--border-focus);
    background: var(--bg-white);
    outline: none;
    box-shadow: 0 0 0 2px rgba(46,139,87,0.15);
}

.budget-editable .budget-amount {
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 600;
    width: 120px;
}

.budget-editable .budget-cofinancing {
    border: 1px solid var(--border);
    background: var(--bg-white);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    width: 120px;
    text-align: right;
    transition: border-color 0.15s;
}

.budget-editable .budget-cofinancing:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 2px rgba(46,139,87,0.15);
}

.budget-delete-row {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.budget-editable tbody tr:hover .budget-delete-row {
    opacity: 0.5;
}

.budget-delete-row:hover {
    opacity: 1 !important;
    color: var(--danger);
}

.budget-add-row-cell {
    padding: 0.35rem 0.5rem !important;
    border-bottom: none;
}

/* ── Markdown format bar ── */
.cell-format-bar {
    display: none;
    padding: 0.2rem 0.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    gap: 0.15rem;
    align-items: center;
    flex-wrap: wrap;
}
.cell--editing .cell-format-bar {
    display: flex;
}
.fmt-btn {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    cursor: pointer;
    color: var(--text);
    line-height: 1.5;
    font-family: var(--font);
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.fmt-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}
.fmt-sep {
    width: 1px;
    height: 13px;
    background: var(--border);
    margin: 0 0.1rem;
    flex-shrink: 0;
}

/* Heading cell */
.cell-heading .cell-content {
    font-size: 1.2rem;
    font-weight: 700;
}

/* Add cell button */
.add-cell-row {
    display: flex;
    justify-content: center;
    padding: 0.5rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.notebook-section:hover .add-cell-row,
.add-cell-row:focus-within {
    opacity: 1;
}

.add-cell-btn {
    background: none;
    border: 1.5px dashed var(--border);
    color: var(--text-muted);
    padding: 0.35rem 1rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
}

.add-cell-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

/* === AI Panel === */
.ai-panel {
    width: var(--ai-panel-w);
    background: var(--bg-white);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    color: var(--text) !important;
}

/* Force readable text colors inside the AI panel.
   The ONLYOFFICE editor injects styles into iframes that override
   normal specificity. Explicit !important rules per element prevent this. */
.ai-panel .ai-suggestion { color: var(--text) !important; }
.ai-panel .ai-suggestion-text { color: var(--text) !important; }
.ai-panel .ai-suggestion-type { color: var(--has-green) !important; }
.ai-panel .ai-suggestion-type.evidence { color: var(--success) !important; }
.ai-panel .ai-suggestion-type.structure { color: #7c3aed !important; }
.ai-panel .ai-suggestion-type.budget { color: var(--warning) !important; }
.ai-panel .ai-suggestion-type.error { color: var(--danger) !important; }
.ai-panel .ai-panel-header h3 { color: var(--text) !important; }
.ai-panel .ai-tab { color: var(--text-muted) !important; }
.ai-panel .ai-tab.active { color: var(--has-green) !important; }
.ai-panel .text-muted { color: var(--text-muted) !important; }
.ai-panel .lit-item { color: var(--text) !important; }
.ai-panel .lit-title { color: var(--text) !important; }
.ai-panel .lit-authors { color: var(--text-muted) !important; }
.ai-panel .btn-primary { color: #fff !important; background-color: var(--has-green) !important; }
.ai-panel .btn-approve-copy { color: var(--has-green) !important; }

.ai-panel[hidden] { display: none; }

.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.ai-panel-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

.ai-panel-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.ai-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 0.5rem;
}

.ai-tab {
    padding: 0.6rem 0.75rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.8rem;
    font-family: var(--font);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.ai-tab:hover { color: var(--text); }
.ai-tab.active {
    color: var(--has-green);
    border-bottom-color: var(--has-green);
    font-weight: 600;
}

.ai-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.ai-tab-content[hidden] { display: none; }

/* AI Suggestion Card */
.ai-suggestion {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text) !important;
}

.ai-suggestion-type {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--has-green) !important;
    margin-bottom: 0.25rem;
}

.ai-suggestion-type.evidence { color: var(--success) !important; }
.ai-suggestion-type.structure { color: #7c3aed !important; }
.ai-suggestion-type.budget { color: var(--warning) !important; }
.ai-suggestion-type.error { color: var(--danger) !important; }

.ai-suggestion-text {
    color: var(--text) !important;
}

.ai-approve-row {
    margin-top: 0.5rem;
}

/* Literature suggestion */
.lit-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    color: var(--text) !important;
}

.lit-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text) !important;
    margin-bottom: 0.2rem;
}

.lit-authors {
    font-size: 0.8rem;
    color: var(--text-muted) !important;
}

.lit-doi {
    font-size: 0.75rem;
    color: var(--primary) !important;
    font-family: var(--font-mono);
}

.lit-relevance {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

/* Language check */
.correction-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.correction-type {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--danger);
    margin-bottom: 0.25rem;
}

.correction-original {
    text-decoration: line-through;
    color: var(--danger);
}

.correction-fix {
    color: var(--success);
    font-weight: 600;
}

.ai-approve-row {
    margin-top: 0.5rem;
    display: flex;
    justify-content: flex-end;
}

.btn-xs {
    font-size: 0.72rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.15s, opacity 0.15s;
}

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

.btn-approve:hover:not(:disabled) {
    opacity: 0.85;
}

.btn-approve:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn-approve-copy {
    background: var(--bg-alt, #f4f4f4);
    color: var(--text-muted, #666);
    border-color: var(--border);
}

.btn-approve-copy:hover {
    background: var(--border);
}

.correction-applied {
    opacity: 0.5;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 9100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] { display: none; }

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
}

.modal-content {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; }

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.translate-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.translate-col h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.translate-lang-select {
    font-size: 0.8rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.translate-text {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    min-height: 150px;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* === Loading States === */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    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); } }

.loading-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1rem;
}

/* === Sidebar Backdrop (mobile overlay) === */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-h);
    background: rgba(0,0,0,0.45);
    z-index: 190;
}

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

/* === Responsive - Tablet (≤900px) === */
@media (max-width: 900px) {
    :root {
        --ai-panel-w: 320px;
    }

    .sidebar {
        position: fixed;
        z-index: 200;
        top: var(--topbar-h);
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: var(--sidebar-w);
        overflow-y: auto;
    }

    /* collapsed = closed on mobile */
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-w); /* keep width so transform works */
        overflow-y: auto;       /* override desktop width:0 rule */
    }

    /* open = visible on mobile */
    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .ai-panel {
        position: fixed;
        z-index: 200;
        top: var(--topbar-h);
        bottom: 0;
        right: 0;
        width: var(--ai-panel-w);
        max-width: 90vw;
    }

    .translate-columns {
        grid-template-columns: 1fr;
    }

    .project-grid {
        grid-template-columns: 1fr;
    }

    .main-content {
        padding: 1rem 1.25rem;
    }

    .editor-actions {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .editor-actions .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.65rem;
    }

    /* Notebook section header: allow wrap on tablet */
    .notebook-section-header {
        flex-wrap: wrap;
    }

    /* Editor dropdowns: ensure they don't overflow off-screen */
    .editor-more-menu {
        right: 0;
        left: auto;
    }

    /* Import URL form: prevent overflow */
    .import-url-form {
        flex-wrap: wrap;
    }
}

/* === Responsive - Mobile (≤600px) === */
@media (max-width: 600px) {
    :root {
        --topbar-h: 54px;
        --ai-panel-w: 100vw;
    }

    /* Topbar */
    .topbar {
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .topbar-left {
        min-width: unset;
        gap: 0.5rem;
    }

    .logo-small span {
        display: none; /* hide text on very small screens */
    }

    .topbar-center {
        flex: 1;
        overflow: hidden;
        font-size: 0.8rem;
        min-width: 0;
    }

    .breadcrumb-current {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
        display: inline-block;
    }

    .topbar-right {
        gap: 0.4rem;
    }

    .user-badge {
        display: none; /* hidden on small screens */
    }

    #btn-admin-panel {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    #btn-logout {
        padding: 0.4rem 0.7rem;
        font-size: 0.8rem;
    }

    /* Sidebar full-width drawer on mobile */
    .sidebar {
        width: min(280px, 85vw);
    }

    /* Main content */
    .main-content {
        padding: 0.85rem 0.85rem;
    }

    /* View header stacks on small screens */
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
    }

    .view-header h2 {
        font-size: 1.15rem;
    }

    /* Editor header */
    .editor-title-row {
        flex-wrap: wrap;
    }

    .editor-title-row h2 {
        font-size: 1rem;
        min-width: 0;
        flex: 1;
    }

    .editor-actions {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.25rem;
        gap: 0.35rem;
        -webkit-overflow-scrolling: touch;
    }

    .editor-actions .btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Form row: single column */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Form card: full width */
    .form-card {
        max-width: 100%;
    }

    /* Login box */
    .login-box {
        padding: 24px 18px;
    }

    /* Notebook */
    .notebook {
        max-width: 100%;
    }

    .cell-gutter {
        width: 28px;
    }

    .cell-content {
        padding: 0.6rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Project grid */
    .project-grid {
        grid-template-columns: 1fr;
    }

    /* Project card */
    .project-card {
        padding: 1rem;
    }

    /* Modal: full-screen on mobile */
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 92dvh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin-top: auto;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .modal-body:last-child {
        padding-bottom: 1.5rem;
    }

    .modal {
        align-items: flex-end;
    }

    /* AI panel full-width on mobile */
    .ai-panel {
        width: 100vw;
        max-width: 100vw;
    }

    /* Section actions hidden by default, shown on tap */
    .section-actions {
        gap: 0.15rem;
    }

    /* Upload zone */
    .upload-zone {
        padding: 1.5rem 1rem;
    }

    /* Toast */
    .toast-container {
        bottom: 1rem;
        right: 0.75rem;
        left: 0.75rem;
    }

    .toast {
        max-width: 100%;
    }

    /* ── Touch-friendly: always show drag handles ── */
    .drag-handle {
        opacity: 1;
    }
    .cell:hover .drag-handle {
        opacity: 1;
    }

    /* ── Always show add-cell buttons ── */
    .add-cell-row {
        opacity: 1;
    }

    /* ── Always show section actions ── */
    .section-actions {
        opacity: 1;
    }

    /* ── Import URL form: stack vertically ── */
    .import-url-form {
        flex-direction: column;
    }
    .import-url-form .form-input {
        width: 100%;
    }

    /* ── Sources URL row: wrap ── */
    .sources-url-row {
        flex-wrap: wrap;
    }

    /* ── Extra URL row: wrap ── */
    .sources-extra-url-row {
        flex-wrap: wrap;
    }

    /* ── AI panel tabs: horizontal scroll ── */
    .ai-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        gap: 0;
    }
    .ai-tabs .ai-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ── Settings tabs: horizontal scroll ── */
    .settings-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .settings-tabs .settings-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ── Import mode tabs: horizontal scroll ── */
    .import-mode-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .import-mode-tabs .login-tab {
        flex-shrink: 0;
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 6px 10px;
    }

    /* ── Cell toolbar: horizontal scroll ── */
    .cell-toolbar {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .cell-toolbar .btn-sm {
        flex-shrink: 0;
    }

    /* ── Cell format bar: scroll ── */
    .cell-format-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Notebook section header: wrap ── */
    .notebook-section-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .notebook-section-header h3 {
        font-size: 1rem;
    }

    /* ── Login tabs: compact ── */
    .login-tabs .login-tab {
        font-size: 0.8rem;
        padding: 6px 8px;
    }

    /* ── Sources block ── */
    .sources-block {
        padding: 0.5rem;
    }

    /* ── Group form row: wrap ── */
    .group-form-row {
        flex-wrap: wrap;
    }
    .group-form-row input[type="text"] {
        min-width: 120px;
    }

    /* ── Share group bar: stack ── */
    .share-group-bar {
        flex-direction: column;
        align-items: stretch;
    }

    /* ── User search bar: stack ── */
    .user-search-bar {
        flex-direction: column;
        align-items: stretch;
    }

    /* ── Budget table: scrollable ── */
    .budget-table {
        font-size: 0.78rem;
    }
    .budget-table th,
    .budget-table td {
        padding: 0.35rem 0.4rem;
    }
    .budget-editable .budget-amount,
    .budget-editable .budget-cofinancing {
        width: 80px;
        font-size: 0.78rem;
    }

    /* ── Context URL bar: stack ── */
    .ctx-url-row {
        flex-wrap: wrap;
    }
    .ctx-add-bar {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    /* ── Editor more menus: ensure within viewport ── */
    .editor-more-menu {
        right: 0;
        left: auto;
        min-width: 140px;
    }

    /* ── Translate columns ── */
    .translate-text {
        min-height: 100px;
        padding: 0.75rem;
        font-size: 0.85rem;
    }

    /* ── Sharing modal ── */
    .share-perm-select {
        font-size: 0.75rem;
        padding: 0.15rem 0.3rem;
    }

    /* ── Checklist tabs: horizontal scroll ── */
    .checklist-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .checklist-tabs .checklist-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ── Checklist add row: wrap ── */
    .checklist-add-row {
        flex-wrap: wrap;
    }
    .checklist-add-input {
        min-width: 120px;
    }

    /* ── Editor body: proper flex overflow ── */
    .editor-body {
        flex: 1;
        overflow-y: auto;
        padding-bottom: 1rem;
    }
}

/* === Toast Notifications === */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-sidebar);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 350px;
}

.toast.success { background: var(--has-green); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: var(--text); }

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

/* === Dev Footer === */
.dev-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--has-darker-green);
    border-top: 1px solid rgba(46, 139, 87, 0.25);
    color: rgba(255, 255, 255, 0.45);
    font-family: var(--font);
    font-size: 0.7rem;
    text-align: center;
    padding: 0.3rem 1rem;
    z-index: 9000;
    letter-spacing: 0.04em;
    user-select: none;
    pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════════════════════
   GROUPS & SHARING & SETTINGS - new feature styles
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── Group filter sidebar ──────────────────────────────────────────────────── */
.group-filter-section {
    padding: 0.5rem 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin-top: 0.5rem;
}
.group-filter-header {
    padding: 0.5rem 0.75rem 0.25rem;
}
.group-filter-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}
.group-filter-list {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0 0.75rem;
}
.group-filter-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.625rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.825rem;
    color: #cbd5e1;
    text-align: left;
    border-radius: var(--radius);
    transition: background 0.15s;
    font-family: var(--font);
}
.group-filter-item:hover { background: rgba(255,255,255,0.1); color: white; }
.group-filter-item.active { background: var(--has-green); color: white; font-weight: 600; }
.group-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--group-color, #6366f1);
}
.group-filter-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.group-filter-count {
    font-size: 0.7rem;
    color: #94a3b8;
    background: rgba(255,255,255,0.1);
    border-radius: 999px;
    padding: 0 0.4rem;
    min-width: 1.4em;
    text-align: center;
}
.group-filter-item.active .group-filter-count {
    color: rgba(255,255,255,0.85);
    background: rgba(0,0,0,0.15);
}
.group-filter-list .text-muted {
    color: #94a3b8;
    padding: 0.5rem 0.625rem;
    font-size: 0.8rem;
}

/* ── Group rows in settings ────────────────────────────────────────────────── */
.group-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0;
    max-height: 220px;
    overflow-y: auto;
}
.group-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background 0.1s, border-color 0.1s;
}
.group-row:hover {
    background: var(--primary-light);
    border-color: rgba(46,139,87,0.25);
}
.group-row-name { flex: 1; font-weight: 500; }
.group-row-count { font-size: 0.78rem; color: var(--text-muted); }
.group-row-icon { font-size: 1rem; }
.group-row-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

.group-create-form {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.group-edit-form {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: var(--primary-light);
    border: 1px solid rgba(46,139,87,0.3);
    border-radius: var(--radius);
}
/* Group form: flex row, properly styled input */
.group-form-row {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    align-items: center;
}
.group-form-row input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: var(--font);
    background: var(--bg-card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.group-form-row input[type="text"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.group-form-row input[type="text"]::placeholder { color: var(--text-muted); }

/* Compact circular colour swatch */
.group-form-row input[type="color"] {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    overflow: hidden;
    transition: border-color 0.15s;
}
.group-form-row input[type="color"]:hover { border-color: var(--border-focus); }
.group-form-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.group-form-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

/* ══════════════════════════════════════════════════════════════════════
   NEW FEATURE STYLES - Advanced features (comments, versions, refs, etc.)
   ══════════════════════════════════════════════════════════════════════ */

/* Cell word count badge */
.cell-word-count {
    font-size: .7rem;
    color: #999;
    padding: 0 4px;
    line-height: 1.4;
    pointer-events: none;
}
.cell-word-count.over-limit {
    color: var(--danger);
    font-weight: 600;
}

/* Section limit badge */
.section-limit-badge {
    font-size: .7rem;
    color: #aaa;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 8px;
}

/* Comment count badge on cell toolbar button */
.comment-count {
    font-size: .7rem;
    background: var(--primary);
    color: #fff;
    border-radius: 8px;
    padding: 0 4px;
    margin-left: 2px;
}

/* Tools tab in AI panel */
.tools-tab-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}
.tools-tab-actions .btn {
    width: 100%;
    text-align: left;
}
#tools-free-text textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color 0.15s;
    background: var(--bg-white);
    resize: vertical;
    min-height: 80px;
    box-sizing: border-box;
}
#tools-free-text textarea:focus {
    outline: none;
    border-color: var(--border-focus);
}

/* ── Side panels (comments / references / activity) ─────────────────── */
.comments-panel,
.references-panel,
.activity-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100%;
    width: 340px;
    background: #fff;
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0,0,0,.10);
    display: flex;
    flex-direction: column;
    z-index: 1100;
    overflow: hidden;
}
.comments-panel[hidden],
.references-panel[hidden],
.activity-panel[hidden] { display: none; }

.comments-panel-header,
.references-panel-header,
.activity-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-light, #f9f9f9);
}
.comments-panel-header h4,
.references-panel-header h4,
.activity-panel-header h4 {
    flex: 1;
    margin: 0;
    font-size: .95rem;
}

/* ── Comment items ──────────────────────────────────────────────────── */
.comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.comment-item {
    background: #f9f9f9;
    border: 1px solid var(--border);
    border-radius: var(--radius, 8px);
    padding: 10px 12px;
}
.comment-item.comment-resolved {
    opacity: .55;
}
.comment-meta {
    display: flex;
    justify-content: space-between;
    font-size: .72rem;
    color: #999;
    margin-bottom: 4px;
}
.comment-author {
    font-weight: 600;
    color: #666;
}
.comment-body {
    font-size: .88rem;
    line-height: 1.5;
    white-space: pre-wrap;
}
.comment-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}
.comment-actions button {
    font-size: .72rem;
    padding: 2px 6px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: #666;
}
.comment-actions button:hover { background: #eee; }

.comments-input-row {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.comment-input {
    resize: none;
    font-size: .88rem;
}

/* ── Version history items ──────────────────────────────────────────── */
.version-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.version-item {
    border: 1px solid var(--border);
    border-radius: var(--radius, 8px);
    padding: 10px 14px;
    background: #fafafa;
}
.version-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.version-time {
    font-size: .72rem;
    color: #aaa;
}
.version-author {
    font-size: .75rem;
    color: #666;
}
.version-preview {
    font-size: .83rem;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.version-rollback-btn {
    font-size: .75rem;
    padding: 3px 8px;
    background: none;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 4px;
    cursor: pointer;
}
.version-rollback-btn:hover { background: var(--primary); color: #fff; }

/* ── Reference items ────────────────────────────────────────────────── */
.ref-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ref-item {
    border: 1px solid var(--border);
    border-radius: var(--radius, 8px);
    padding: 10px 12px;
    background: #fafafa;
}
.ref-key-badge {
    display: inline-block;
    font-size: .7rem;
    background: #e8f0fe;
    color: #3367d6;
    border-radius: 4px;
    padding: 1px 6px;
    font-family: monospace;
    margin-bottom: 4px;
}
.ref-title {
    font-size: .88rem;
    font-weight: 600;
    line-height: 1.4;
}
.ref-meta {
    font-size: .75rem;
    color: #888;
    margin-top: 2px;
}
.ref-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}
.ref-actions button {
    font-size: .72rem;
    padding: 2px 6px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: #666;
}
.ref-actions button:hover { background: #eee; }

/* ── Activity items ─────────────────────────────────────────────────── */
.activity-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.activity-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 8px 10px;
    border-radius: var(--radius, 8px);
    background: #fafafa;
    border: 1px solid var(--border);
}
.activity-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}
.activity-body {
    flex: 1;
    min-width: 0;
}
.activity-action {
    font-size: .83rem;
    font-weight: 500;
    line-height: 1.4;
}
.activity-meta {
    font-size: .72rem;
    color: #aaa;
    margin-top: 2px;
}

/* ── Checklist items ────────────────────────────────────────────────── */
.checklist-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 360px;
    overflow-y: auto;
}
.checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius, 8px);
    background: #fafafa;
}
.checklist-item.checklist-checked {
    background: #f0fff4;
    border-color: #b7efcc;
    opacity: .8;
}
.checklist-cb {
    width: 16px;
    height: 16px;
    accent-color: var(--has-green);
    cursor: pointer;
    flex-shrink: 0;
}
.checklist-label {
    flex: 1;
    font-size: .88rem;
    line-height: 1.4;
}
.checklist-item.checklist-checked .checklist-label {
    text-decoration: line-through;
    color: #aaa;
}
.checklist-delete-btn {
    font-size: .7rem;
    padding: 2px 5px;
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    border-radius: 3px;
}
.checklist-delete-btn:hover { background: #fee; color: var(--danger); }
.checklist-tab {
    border: 1px solid var(--border);
    background: #f5f5f5;
    color: #555;
    transition: background .15s, color .15s;
}
.checklist-tab.active,
.checklist-tab:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── modal-sm variant ───────────────────────────────────────────────── */
.modal-sm .modal-content,
.modal-content.modal-sm {
    max-width: 420px;
}

/* ── Mobile adjustments ─────────────────────────────────────────────── */
@media (max-width: 600px) {
    .comments-panel,
    .references-panel,
    .activity-panel {
        width: 100vw;
    }
}

/* ── Settings modal ────────────────────────────────────────────────────────── */
.modal-content--wide { max-width: 700px; width: 90vw; }
.modal-content--sm   { max-width: 420px; width: 92vw; }

.settings-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}
.settings-tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius) var(--radius) 0 0;
    transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.settings-pane { display: block; }
.settings-pane[hidden] { display: none; }

.settings-msg {
    padding: 0.6rem 0.875rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.settings-msg.success { background: var(--success-light, #d1fae5); color: #065f46; }
.settings-msg.error   { background: #fee2e2; color: #991b1b; }

.settings-groups-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
@media (max-width: 600px) {
    .settings-groups-cols { grid-template-columns: 1fr; gap: 1rem; }
}
.settings-groups-col {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
}
.settings-groups-col h4 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
    color: var(--text);
    letter-spacing: 0.01em;
}
.settings-groups-col > .text-muted {
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}
.settings-groups-col .group-list:empty + p,
.settings-groups-col .group-list p {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.4rem 0;
    margin: 0;
}

/* ── Permission badges ─────────────────────────────────────────────────────── */
.perm-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.perm-badge--read  { background: #dbeafe; color: #1d4ed8; }
.perm-badge--write { background: #fef3c7; color: #92400e; }
.perm-badge--admin { background: #fee2e2; color: #991b1b; }
.perm-badge--owner { background: #ede9fe; color: #5b21b6; }

/* ── Owner badge on shared project cards ───────────────────────────────────── */
.owner-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.1rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
}
.card-badges {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

/* ── Dashboard section header (My Projects / Shared) ──────────────────────── */
.dashboard-section-header {
    padding: 0.5rem 0 0.25rem;
}
.dashboard-section-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Share modal ─────────────────────────────────────────────────────────────*/
.share-section { margin-bottom: 0.5rem; }
.share-section h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.5rem; }
.share-list { display: flex; flex-direction: column; gap: 0.4rem; min-height: 2rem; }
.share-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.share-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.share-avatar--group { background: var(--bg-sidebar); font-size: 0.95rem; }
.share-target-info { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.share-perm-select { width: auto; font-size: 0.8rem; padding: 0.2rem 0.4rem; }
.share-group-bar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ── User group member list ────────────────────────────────────────────────── */
.member-list { display: flex; flex-direction: column; gap: 0.4rem; min-height: 2rem; }
.member-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.member-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.member-info { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }

/* ── User search bar ───────────────────────────────────────────────────────── */
.user-search-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.user-search-bar input { flex: 1; min-width: 0; }
.search-results { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.25rem; }
.user-search-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    background: var(--bg-main);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.user-search-row > span:first-of-type { flex: 1; }

/* ── Group picker checkboxes ───────────────────────────────────────────────── */
.gp-group-list { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.25rem 0; }
.gp-group-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.12s;
}
.gp-group-option:hover { background: var(--bg-hover); }
.gp-group-option input[type="checkbox"] { cursor: pointer; }

/* ── btn-xs (extra small button) ──────────────────────────────────────────── */
.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
    min-height: unset;
    line-height: 1.4;
}

/* ── form-select sizes ─────────────────────────────────────────────────────── */
.form-select--sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.82rem;
}

/* ── text helpers ──────────────────────────────────────────────────────────── */
.text-small { font-size: 0.8rem; }
.mt-8 { margin-top: 8px; }

.dev-footer strong {
    color: rgba(255, 255, 255, 0.75);
    font-weight: 700;
}

.dev-footer__divider {
    margin: 0 0.5em;
    opacity: 0.35;
}

.dev-footer .dev-footer__badge {
    display: inline-block;
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 3px;
    padding: 0.05em 0.45em;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    vertical-align: middle;
    margin-left: 0.2em;
}

.dev-footer .dev-footer__warning {
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
}

/* === Form hint === */
.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

/* === Inline alert messages === */
.success-msg {
    color: var(--success);
    background: #dcfce7;
    border: 1px solid #86efac;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
}

.error-msg {
    color: var(--danger);
    background: #fee2e2;
    border: 1px solid #fca5a5;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
}

/* ── Forgot password link on login pane ──────────────────────────── */
.forgot-link-row {
    margin-top: 12px;
    text-align: center;
}
.forgot-link {
    font-size: 0.85rem;
    color: var(--has-green);
    text-decoration: none;
    font-weight: 500;
}
.forgot-link:hover {
    text-decoration: underline;
    color: var(--has-green-hover);
}

/* ── Forgot password page ────────────────────────────────────────── */
.reset-description {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}
.forgot-form {
    margin-bottom: 0.5rem;
}
.forgot-form .alert {
    margin-bottom: 1rem;
}
#fp-success .success-msg {
    margin-bottom: 1.5rem;
}

/* === Password reset page === */
.reset-card {
    max-width: 420px;
    margin: 6rem auto;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
}

.reset-card h1 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    color: var(--has-dark-green);
}

.reset-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.reset-logo img { height: 36px; }

.reset-logo span {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--has-dark-green);
}

.back-link {
    display: inline-block;
    margin-top: 1.5rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}

.back-link:hover { text-decoration: underline; }

/* ── Reset page responsive ────────────────────────────────────────── */
@media (max-width: 600px) {
    .reset-card {
        margin: 2rem 1rem;
        padding: 1.5rem 1.25rem;
    }
    .reset-card h1 {
        font-size: 1.2rem;
    }
    .reset-logo {
        margin-bottom: 1.25rem;
    }
    .reset-logo span {
        font-size: 1rem;
    }
}

/* ── CSP-safe utility classes (replace inline style attributes) ─────────── */
.checklist-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.checklist-progress-bar {
    background: #eee;
    border-radius: 4px;
    height: 6px;
    margin-bottom: 8px;
}
#checklist-progress {
    height: 100%;
    background: var(--has-green);
    border-radius: 4px;
    transition: width .3s;
    width: 0%;
}
.checklist-stats {
    text-align: right;
    font-size: .8rem;
    color: #666;
    margin-bottom: 8px;
}
.checklist-add-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.checklist-add-input {
    flex: 1;
}
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
}
.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}
.empty-state-title {
    margin-bottom: 0.5rem;
}
.dashboard-section-header {
    grid-column: 1 / -1;
}
.text-right {
    text-align: right;
}
.panel-empty {
    padding: 12px;
}
.ai-panel-title {
    margin: 0 0 8px;
}
.btn-danger-solid {
    color: #fff;
    background: #dc3545;
    border-color: #dc3545;
}
.modal-divider {
    margin: 12px 0;
}
.section-desc-note {
    margin: 0.25rem 0 0;
}
.toast-hidden {
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
}
