/* ───── Design tokens ───── */
:root {
    --color-bg:           #f7f8fb;
    --color-bg-grad:      radial-gradient(ellipse at top, #eef2ff 0%, #f7f8fb 50%);
    --color-surface:      #ffffff;
    --color-surface-2:    #f3f5f9;
    --color-surface-3:    #e9edf3;

    --color-text:         #0f172a;
    --color-text-muted:   #475569;
    --color-text-soft:    #94a3b8;
    --color-placeholder:  #cbd5e1;

    --color-border:       #e2e8f0;
    --color-border-hover: #cbd5e1;
    --color-border-focus: #4f46e5;

    --color-primary:      #4f46e5;
    --color-primary-hov:  #4338ca;
    --color-primary-soft: #eef2ff;
    --color-primary-fg:   #ffffff;
    --color-accent:       #7c3aed;
    --gradient-primary:   linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);

    --color-success:      #10b981;
    --color-success-soft: #ecfdf5;
    --color-danger:       #ef4444;
    --color-danger-bg:    #fef2f2;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-pill: 999px;

    --font-xs: 12px;
    --font-sm: 13px;
    --font-md: 14px;
    --font-lg: 16px;
    --font-xl: 22px;
    --font-2xl: 28px;

    --shadow-xs: 0 1px 2px 0 rgb(15 23 42 / 0.04);
    --shadow-sm: 0 1px 3px 0 rgb(15 23 42 / 0.06), 0 1px 2px -1px rgb(15 23 42 / 0.04);
    --shadow-md: 0 4px 12px -2px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.04);
    --shadow-lg: 0 20px 40px -12px rgb(15 23 42 / 0.12), 0 8px 16px -8px rgb(15 23 42 / 0.06);
    --shadow-focus: 0 0 0 4px rgb(79 70 229 / 0.18);
    --shadow-primary: 0 4px 14px -4px rgb(79 70 229 / 0.4);

    --grid-template: 1fr 36px 1fr;
    --content-max: 1180px;
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ───── Base ───── */
* { box-sizing: border-box; }

html { font-size: 14px; }

body {
    margin: 0;
    background: var(--color-bg);
    background-image: var(--color-bg-grad);
    background-attachment: fixed;
    color: var(--color-text);
    font-family:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: var(--font-md);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.page {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-8) var(--space-6) var(--space-10);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.form-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* ───── Auth bar ───── */
.auth-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.auth-user {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.auth-avatar {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: var(--gradient-primary);
    color: var(--color-primary-fg);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: var(--font-md);
    box-shadow: var(--shadow-primary);
}

.auth-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.2;
}

.auth-email {
    color: var(--color-text);
    font-weight: 600;
    font-size: var(--font-sm);
}

.auth-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--font-xs);
    color: var(--color-text-soft);
}

.auth-dot {
    width: 6px;
    height: 6px;
    background: var(--color-success);
    border-radius: var(--radius-pill);
    box-shadow: 0 0 0 3px rgb(16 185 129 / 0.18);
}

/* ───── Page hero ───── */
.page-hero {
    text-align: center;
    padding: var(--space-2) 0 var(--space-4);
}

.page-title {
    margin: 0 0 var(--space-2);
    font-size: var(--font-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.page-subtitle {
    margin: 0;
    font-size: var(--font-md);
    color: var(--color-text-muted);
}

/* ───── Buttons ───── */
.btn-google {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 500;
    font-size: var(--font-sm);
    text-decoration: none;
    box-shadow: var(--shadow-xs);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.btn-google:hover {
    border-color: var(--color-border-hover);
    box-shadow: var(--shadow-sm);
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-2) var(--space-3);
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: var(--font-sm);
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.btn-ghost:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--gradient-primary);
    color: var(--color-primary-fg);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: var(--font-md);
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px -4px rgb(79 70 229 / 0.5);
}

.btn-primary:active { transform: translateY(0); }

.btn-primary:disabled,
.btn-primary[disabled] {
    background: var(--color-surface-3) !important;
    background-image: none !important;
    color: var(--color-text-soft) !important;
    cursor: not-allowed;
    box-shadow: none !important;
    transform: none !important;
    pointer-events: none;
}

.btn-primary:disabled .btn-arrow,
.btn-primary:disabled .btn-icon,
.btn-primary[disabled] .btn-arrow,
.btn-primary[disabled] .btn-icon { transform: none; }

.btn-primary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn-arrow,
.btn-icon {
    transition: transform var(--transition);
}

.btn-icon {
    display: inline-block;
    vertical-align: -2px;
}

.btn-primary:hover .btn-arrow { transform: translateX(3px); }
.btn-export:hover .btn-icon { transform: translateY(2px); }

/* ───── Tab bar (top-level) ───── */
.tab-bar {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-8);
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--space-2);
}

.tab-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: transparent;
    border: none;
    padding: var(--space-3) var(--space-5) var(--space-4);
    margin-bottom: -1px;
    font-family: inherit;
    font-size: var(--font-md);
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color var(--transition);
}

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

.tab-btn:focus-visible {
    outline: none;
    color: var(--color-primary);
}

.tab-btn::after {
    content: '';
    position: absolute;
    left: var(--space-5);
    right: var(--space-5);
    bottom: 0;
    height: 2px;
    background: transparent;
    border-radius: 2px;
    transition: background var(--transition);
}

.tab-btn.is-active {
    color: var(--color-primary);
    font-weight: 600;
}

.tab-btn.is-active::after {
    background: var(--color-primary);
}

.tab-icon {
    flex-shrink: 0;
    opacity: 0.75;
}

.tab-btn.is-active .tab-icon { opacity: 1; }

/* ───── Merge tab ───── */
.merge-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.dropzone {
    background: var(--color-surface);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-10) var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.dropzone:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
}

.dropzone.is-drag-over {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    box-shadow: var(--shadow-focus);
}

.dropzone-icon {
    color: var(--color-primary);
    margin-bottom: var(--space-3);
}

.dropzone-text {
    font-size: var(--font-lg);
    color: var(--color-text);
    margin: 0 0 var(--space-1);
}

.dropzone-text b { color: var(--color-primary); }

.dropzone-subtext {
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    margin: 0 0 var(--space-3);
}

.dropzone-link {
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-weight: 600;
    font-size: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.dropzone-hint {
    font-size: var(--font-xs);
    color: var(--color-text-soft);
    margin: 0;
}

.merge-banner {
    /* uses .banner-* modifier classes for color */
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    font-weight: 500;
}

.banner-warning {
    border: 1px solid #f59e0b;
    color: #b45309;
    background: #fffbeb;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.file-list:empty { display: none; }

.file-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}

.file-icon { color: var(--color-primary); flex-shrink: 0; }

.file-name {
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: var(--font-xs);
    color: var(--color-text-soft);
    font-variant-numeric: tabular-nums;
}

.file-remove {
    background: transparent;
    border: none;
    color: var(--color-text-soft);
    font-size: 20px;
    line-height: 1;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.file-remove:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.merge-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--space-2);
}

.btn-merge:disabled { cursor: not-allowed; }
.btn-merge:hover:not(:disabled) .btn-icon { transform: translateY(2px); }

/* ───── Segmented control ───── */
.toolbar {
    display: flex;
    justify-content: center;
}

.segmented {
    display: inline-flex;
    padding: 5px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    gap: 2px;
    box-shadow: var(--shadow-xs);
}

.segmented-option {
    padding: var(--space-2) var(--space-6);
    cursor: pointer;
    border-radius: var(--radius-pill);
    font-weight: 500;
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    transition: color var(--transition), background var(--transition), box-shadow var(--transition);
    user-select: none;
}

.segmented-option input { display: none; }

.segmented-option:hover { color: var(--color-text); }

.segmented-option.is-active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

/* ───── Link import row ───── */
.link-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-3) var(--space-4) var(--space-3) var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.link-row:focus-within {
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.field-label {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    padding-right: var(--space-2);
    letter-spacing: 0.01em;
}

/* ───── Generic text input ───── */
.text-input {
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--font-md);
    width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.text-input::placeholder { color: var(--color-placeholder); }

.text-input:focus { outline: none; }

/* ───── Banner ───── */
.banner {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    font-weight: 500;
}

.banner-error {
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    background: var(--color-danger-bg);
}

/* ───── Block section ───── */
.block-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--space-6);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    position: relative;
}

/* Combined sticky head — block summary (badge + title + meta) above chip row */
.block-sticky-head {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--color-surface);
    margin: calc(var(--space-6) * -1);
    margin-bottom: 0;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    box-shadow: 0 4px 8px -6px rgb(15 23 42 / 0.1);
}

/* Top row of the sticky head: block summary on the left, actions on the right */
.block-head-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.block-summary {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.block-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
    margin-left: auto;
}

.btn-export {
    min-width: 150px;
    justify-content: center;
}

.block-badge {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: var(--gradient-primary);
    color: var(--color-primary-fg);
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: var(--font-lg);
    box-shadow: var(--shadow-primary);
    flex-shrink: 0;
}

.block-title {
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.block-meta {
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.block-stat b {
    color: var(--color-text);
    font-weight: 700;
}

.block-stat-sep {
    color: var(--color-text-soft);
}

/* ───── Chip row (inside sticky head) ───── */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: flex-start;
    justify-content: flex-start;
    max-height: 120px;
    overflow-y: auto;
    padding-right: var(--space-2);
}

.chip-row::-webkit-scrollbar { width: 6px; }
.chip-row::-webkit-scrollbar-thumb {
    background: var(--color-border-hover);
    border-radius: 3px;
}

/* ───── Chip ───── */
.chip {
    padding: 6px var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    font-size: var(--font-xs);
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: 600;
    white-space: pre-line;
    line-height: 1.3;
    box-shadow: var(--shadow-xs);
}

.chip-draggable {
    cursor: grab;
    user-select: none;
    transition: all var(--transition);
}

.chip-draggable:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-soft);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.chip-draggable:active { cursor: grabbing; transform: translateY(0); }

.chip-draggable.is-dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

/* ───── Drop zone ───── */
.drop-zone {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: var(--space-1) var(--space-3);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    transition: all var(--transition);
}

.drop-zone .drop-chip { display: none; }
.drop-zone-filled .drop-empty { display: none; }
.drop-zone-filled .drop-chip { display: flex; }

.drop-zone-filled {
    border-style: solid;
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    padding: 0 var(--space-2) 0 var(--space-3);
    box-shadow: var(--shadow-xs);
}

.drop-zone.drag-over {
    border-style: solid;
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    box-shadow: var(--shadow-focus);
    transform: scale(1.01);
}

.drop-empty {
    color: var(--color-placeholder);
    font-size: var(--font-sm);
    font-style: italic;
    user-select: none;
    pointer-events: none;
}

.drop-chip {
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 0;
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-size: var(--font-sm);
    font-weight: 600;
}

.drop-chip-text {
    white-space: pre-line;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.drop-chip-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: rgb(79 70 229 / 0.12);
    color: var(--color-primary);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    font-family: inherit;
    font-weight: 600;
    transition: all var(--transition);
    flex-shrink: 0;
}

.drop-chip-clear:hover {
    background: var(--color-danger);
    color: var(--color-primary-fg);
    transform: rotate(90deg);
}

/* ───── Mapping grid ───── */
.grid-header {
    display: grid;
    grid-template-columns: var(--grid-template);
    gap: var(--space-4);
    text-align: center;
    font-weight: 700;
    font-size: 11px;
    color: var(--color-text-soft);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0 var(--space-2);
}

.grid-header > div:nth-child(1) { text-align: left; }
.grid-header > div:nth-child(3) { text-align: left; }

.mapping-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mapping-row {
    display: grid;
    grid-template-columns: var(--grid-template);
    gap: var(--space-4);
    align-items: center;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.mapping-row:hover { background: var(--color-surface-2); }

.arrow {
    text-align: center;
    color: var(--color-text-soft);
    font-size: var(--font-lg);
    font-weight: 300;
    transition: color var(--transition), transform var(--transition);
}

.mapping-row:hover .arrow {
    color: var(--color-primary);
    transform: translateX(2px);
}

.target-pill {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    font-weight: 500;
    color: var(--color-text);
    font-size: var(--font-md);
    user-select: none;
}

/* ───── Modal dialog ───── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

.modal-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-6);
    width: 460px;
    max-width: calc(100vw - 32px);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    animation: scaleIn 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-title {
    margin: 0;
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--color-text);
}

.modal-text {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-md);
    line-height: 1.5;
}

.modal-text b { color: var(--color-primary); }

.bulk-progress {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

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

.bulk-progress-meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--font-sm);
}

.bulk-progress-track {
    width: 100%;
    height: 8px;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--color-border);
}

.bulk-progress-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--color-primary);
    transition: width 220ms ease;
}

.modal-warning-box {
    margin: var(--space-2) 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid #fcd34d;
    border-radius: var(--radius-md);
    background: #fef3c7;
    color: #78350f;
    font-size: var(--font-sm);
}

.modal-warning-box ul {
    margin: var(--space-2) 0 0 var(--space-4);
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
}

.modal-warning-box li {
    margin: 2px 0;
}

.modal-note {
    font-size: var(--font-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-2);
}

.modal-ok {
    margin: var(--space-2) 0;
    padding: var(--space-3) var(--space-4);
    border: 1px solid #6ee7b7;
    border-radius: var(--radius-md);
    background: #d1fae5;
    color: #065f46;
    font-size: var(--font-sm);
}

.modal-input {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.modal-input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.modal-label {
    font-size: var(--font-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: var(--space-2);
}

.modal-segmented {
    display: inline-flex;
    padding: 2px;
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    gap: 2px;
    align-self: flex-start;
}

.modal-segmented-option {
    cursor: pointer;
    padding: 6px 14px;
    border-radius: calc(var(--radius-md) - 4px);
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}

.modal-segmented-option:hover {
    color: var(--color-text);
}

.modal-segmented-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.modal-segmented-option:has(input:checked) {
    background: var(--color-surface);
    color: var(--color-primary);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ───── Saved sheets directory ───── */
.saved-sheets {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-xs);
}

.saved-sheets-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.saved-sheets-title {
    margin: 0;
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--color-text);
}

.saved-sheets-sub {
    margin: 2px 0 0;
    font-size: var(--font-xs);
    color: var(--color-text-muted);
}

.saved-sheets-empty {
    margin: 0;
    padding: var(--space-3);
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    background: var(--color-surface-2);
    border-radius: var(--radius-sm);
}

.saved-sheets-filter {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.saved-sheets-filter:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.saved-sheets-no-match {
    margin: 0;
    padding: var(--space-3);
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
}

/* Row grid template shared by header + data so columns line up. */
.saved-sheet-header,
.saved-sheet-row {
    display: grid;
    grid-template-columns: 36px minmax(140px, 1.3fr) 96px minmax(110px, 0.9fr) minmax(180px, 2fr) 110px;
    align-items: center;
    gap: var(--space-4);
}

/* `display: grid` above overrides the user-agent's `[hidden] { display: none }`,
   so filter JS toggling `row.hidden` had no visible effect. Force hidden here. */
.saved-sheet-row[hidden] {
    display: none;
}

.saved-sheets-table {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-surface);
}

.saved-sheet-header {
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.saved-sheets-list {
    display: flex;
    flex-direction: column;
    max-height: 280px;
    overflow-y: auto;
}

.saved-sheet-row {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background var(--transition);
}

.saved-sheet-row:last-child {
    border-bottom: none;
}

.saved-sheet-row:hover {
    background: var(--color-surface-2);
}

.saved-sheet-row.is-active {
    background: var(--color-primary-soft, rgba(99, 102, 241, 0.12));
    box-shadow: inset 4px 0 0 0 var(--color-primary);
}

.saved-sheet-row.is-active .saved-sheet-name {
    color: var(--color-primary);
    font-weight: 700;
}

.saved-sheet-row.is-active .saved-sheet-link {
    color: var(--color-primary);
    font-weight: 600;
}

.saved-sheet-row.is-active:hover {
    background: var(--color-primary-soft, rgba(99, 102, 241, 0.12));
}

.saved-sheet-name {
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-sheet-partner {
    color: var(--color-text);
    font-size: var(--font-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-sheet-loai-hinh {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.loai-hinh-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: var(--font-xs);
    font-weight: 600;
    line-height: 1.4;
}

.loai-hinh-cao_tang {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-primary);
}

.loai-hinh-thap_tang {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}

.saved-sheet-link {
    color: var(--color-text-muted);
    font-size: var(--font-xs);
    font-family: ui-monospace, "SF Mono", Monaco, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-sheet-actions {
    display: flex;
    gap: var(--space-1);
    justify-content: flex-end;
}

.saved-sheet-actions .btn-icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.saved-sheet-actions .btn-icon-only:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.saved-sheet-actions .btn-saved-delete:hover {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
}

.saved-sheet-check-cell {
    display: flex;
    align-items: center;
    justify-content: center;
}

.saved-sheet-check-cell input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.saved-sheets-head-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.bulk-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.bulk-toolbar .bulk-count {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--color-primary);
}

.bulk-divider {
    width: 1px;
    height: 22px;
    background: var(--color-border);
    margin: 0 2px;
}

.btn-bulk-export {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-primary);
    color: #fff;
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), filter var(--transition);
}

.btn-bulk-export:hover {
    filter: brightness(0.95);
}

.btn-bulk-export:disabled,
.btn-bulk-export:disabled:hover {
    background: var(--color-surface-2);
    border-color: var(--color-border);
    color: var(--color-text-muted);
    cursor: not-allowed;
    filter: none;
}


.saved-sheets-skipped-banner {
    margin-top: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid #fcd34d;
    border-radius: var(--radius-md);
    background: #fef3c7;
    color: #78350f;
    font-size: var(--font-sm);
}

.saved-sheets-skipped-banner ul {
    margin: var(--space-2) 0 0 var(--space-4);
    padding: 0;
}

.saved-sheets-skipped-banner li {
    margin: 2px 0;
}

/* ───── Admin page ───── */
.admin-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    margin-left: 8px;
    border-radius: var(--radius-pill);
    background: rgba(99, 102, 241, 0.10);
    color: var(--color-primary);
    border: 1px solid rgba(99, 102, 241, 0.25);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.4;
    vertical-align: middle;
}

.auth-actions {
    display: flex;
    gap: var(--space-1);
    align-items: center;
}

.auth-actions form {
    margin: 0;
}

.auth-actions .btn-ghost-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}

.admin-filters {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.admin-filters .saved-sheets-filter {
    flex: 1;
    margin: 0;
}

.admin-select {
    padding: 0 var(--space-3);
    height: 38px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-size: var(--font-sm);
    color: var(--color-text);
    cursor: pointer;
}

.admin-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Admin row: check + name + loai + partner + owner + link + telegram + actions */
.admin-table .saved-sheet-header,
.admin-table .saved-sheet-row {
    grid-template-columns: 36px minmax(140px, 1.2fr) 96px minmax(110px, 0.8fr) minmax(140px, 1fr) minmax(160px, 1.4fr) minmax(120px, 0.9fr) 76px;
}

.saved-sheet-owner {
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.telegram-chat-input {
    width: 100%;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-sm);
}

.telegram-chat-input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-focus);
}

.telegram-chat-input.is-saving {
    color: var(--color-text-muted);
}

.telegram-chat-input.is-saved {
    border-color: #10b981;
}

.telegram-chat-input.is-error {
    border-color: #ef4444;
}

.btn-bulk-transfer {
    background: #0ea5e9;
    border-color: #0ea5e9;
}

/* ───── Loading overlay ───── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-overlay.is-visible { display: flex; }

.loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-8) var(--space-10);
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    animation: scaleIn 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-primary-soft);
    border-top-color: var(--color-primary);
    border-right-color: var(--color-accent);
    border-radius: var(--radius-pill);
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin: 0;
    color: var(--color-text);
    font-weight: 700;
    font-size: var(--font-lg);
    letter-spacing: -0.01em;
}

.loading-subtext {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
}

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

/* ───── Status bar ───── */
.status-bar {
    text-align: center;
    color: var(--color-text-soft);
    font-size: var(--font-xs);
    padding: var(--space-4) 0 0;
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-2);
}

.admin-settings {
    gap: var(--space-3);
}

.admin-settings-textarea {
    width: 100%;
    min-height: 72px;
    resize: vertical;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    font: inherit;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-surface);
}

.admin-settings-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.admin-settings-status {
    margin: 0;
    color: var(--color-success);
    font-size: var(--font-sm);
}

.admin-settings-status.is-error {
    color: var(--color-danger);
}

/* ───── Login page ───── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-6);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: var(--space-8);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    text-align: center;
}

.login-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    background: var(--gradient-primary);
    color: var(--color-primary-fg);
    border-radius: var(--radius-lg);
    font-weight: 700;
    font-size: var(--font-lg);
    letter-spacing: 1px;
    box-shadow: var(--shadow-primary);
}

.login-title {
    margin: 0;
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--color-text);
}

.login-subtitle {
    margin: 0;
    font-size: var(--font-sm);
    color: var(--color-text-muted);
}

.btn-google-lg {
    width: 100%;
    justify-content: center;
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-md);
}

.login-hint {
    margin: 0;
    font-size: var(--font-xs);
    color: var(--color-text-soft);
    text-align: center;
    line-height: 1.5;
}
