/* STORM ECONOMICS — Multi-Theme Spreadsheet CSS (Dark/Light/Black) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ============================================================
   DARK THEME (по умолчанию)
   ============================================================ */
:root,
[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2333;
    --bg-elevated: #21283b;
    --bg-cell: #141a24;
    --bg-cell-selected: #1a2744;
    --bg-cell-hover: #161e30;
    --bg-header: #131921;
    --bg-header-hover: #1a2233;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --accent-dim: #1f3a5f;
    --accent-glow: rgba(88, 166, 255, 0.15);
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --border: #30363d;
    --border-active: #58a6ff;
    --border-subtle: #21262d;
    --grid-line: #1e252f;
    --grid-header-bg: #131921;
    --grid-header-text: #8b949e;
    --grid-selection: rgba(88, 166, 255, 0.12);
    --grid-selection-border: #58a6ff;
    --lock-bg: rgba(248, 81, 73, 0.08);
    --lock-border: rgba(248, 81, 73, 0.25);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.15);
    --btn-primary-bg: linear-gradient(135deg, #2d5fa1, #58a6ff);
    --btn-primary-bg-hover: linear-gradient(135deg, #3a6bb5, #79b8ff);
    --picker-bg: #161b22;
    --picker-border: #30363d;
}

/* ============================================================
   LIGHT THEME (Светлая)
   ============================================================ */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #eef1f5;
    --bg-elevated: #e8ecf1;
    --bg-cell: #ffffff;
    --bg-cell-selected: #d8e8fc;
    --bg-cell-hover: #edf4fc;
    --bg-header: #f0f3f6;
    --bg-header-hover: #e3e8ec;
    --accent: #0969da;
    --accent-hover: #0550ae;
    --accent-dim: #ddf4ff;
    --accent-glow: rgba(9, 105, 218, 0.1);
    --success: #1a7f37;
    --warning: #9a6700;
    --danger: #cf222e;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #8b949e;
    --border: #d0d7de;
    --border-active: #0969da;
    --border-subtle: #e1e4e8;
    --grid-line: #d8dee4;
    --grid-header-bg: #f0f3f6;
    --grid-header-text: #656d76;
    --grid-selection: rgba(9, 105, 218, 0.1);
    --grid-selection-border: #0969da;
    --lock-bg: rgba(207, 34, 46, 0.06);
    --lock-border: rgba(207, 34, 46, 0.2);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 20px rgba(9, 105, 218, 0.1);
    --btn-primary-bg: linear-gradient(135deg, #0550ae, #0969da);
    --btn-primary-bg-hover: linear-gradient(135deg, #0969da, #218bff);
    --picker-bg: #ffffff;
    --picker-border: #d0d7de;
}

/* ============================================================
   BLACK THEME (Чёрная AMOLED)
   ============================================================ */
[data-theme="black"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #111111;
    --bg-elevated: #1a1a1a;
    --bg-cell: #050505;
    --bg-cell-selected: #0d1f3c;
    --bg-cell-hover: #0a1020;
    --bg-header: #080808;
    --bg-header-hover: #121212;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --accent-dim: #0d2240;
    --accent-glow: rgba(88, 166, 255, 0.2);
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #3d444d;
    --border: #1e1e1e;
    --border-active: #58a6ff;
    --border-subtle: #151515;
    --grid-line: #141414;
    --grid-header-bg: #080808;
    --grid-header-text: #8b949e;
    --grid-selection: rgba(88, 166, 255, 0.15);
    --grid-selection-border: #58a6ff;
    --lock-bg: rgba(248, 81, 73, 0.1);
    --lock-border: rgba(248, 81, 73, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.2);
    --btn-primary-bg: linear-gradient(135deg, #1a3a6a, #58a6ff);
    --btn-primary-bg-hover: linear-gradient(135deg, #2d5fa1, #79b8ff);
    --picker-bg: #0a0a0a;
    --picker-border: #1e1e1e;
}

/* ============================================================
   COMMON VARIABLES
   ============================================================ */
:root {
    --ref-color-1: #58a6ff;
    --ref-color-2: #f97583;
    --ref-color-3: #85e89d;
    --ref-color-4: #ffab70;
    --ref-color-5: #b392f0;
    --ref-color-6: #79b8ff;
    --ref-color-7: #ffdf5d;
    --ref-color-8: #f692ce;
    --header-height: 48px;
    --toolbar-height: 44px;
    --formula-bar-height: 34px;
    --sheet-tabs-height: 36px;
    --cell-default-width: 100px;
    --cell-default-height: 28px;
    --row-header-width: 46px;
    --font-family: 'Century Gothic', 'CenturyGothic', 'AppleGothic', 'Inter', sans-serif;
    --font-mono: 'Consolas', 'Monaco', monospace;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
    --transition-fast: 0.12s ease;
    --transition-normal: 0.2s ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    -webkit-font-smoothing: antialiased
}

/* ─── Layout ──────────────────────── */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden
}

.login-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 30% 40%, var(--accent-dim) 0%, transparent 50%), radial-gradient(ellipse at 70% 80%, rgba(248, 81, 73, 0.05) 0%, transparent 50%)
}

.login-card {
    position: relative;
    z-index: 1;
    width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 32px;
    box-shadow: var(--shadow-lg), var(--shadow-glow)
}

.login-card h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent
}

.login-card .subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 24px
}

/* Auth tabs */
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border)
}

.auth-tab {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition-fast)
}

.auth-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent)
}

.auth-tab:hover {
    color: var(--text-primary)
}

.form-group {
    margin-bottom: 16px
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .8px
}

.form-group input[type=text],
.form-group input[type=password] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 13px;
    transition: border var(--transition-fast);
    outline: none
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow)
}

.form-error {
    color: var(--danger);
    font-size: 11px;
    margin-top: 8px;
    min-height: 16px
}

/* ─── Buttons ─────────────────────── */
.btn {
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: #fff
}

.btn-primary:hover {
    background: var(--btn-primary-bg-hover);
    transform: translateY(-1px)
}

.btn-primary:disabled {
    opacity: .5;
    transform: none
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border)
}

.btn-secondary:hover {
    background: var(--bg-elevated);
    border-color: var(--accent)
}

.btn-danger {
    background: rgba(248, 81, 73, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 81, 73, 0.25)
}

.btn-danger:hover {
    background: rgba(248, 81, 73, 0.25)
}

.btn-sm {
    padding: 4px 10px;
    font-size: 11px
}

.btn-block {
    width: 100%;
    justify-content: center
}

/* ─── Main App Layout ─────────────── */
.main-app {
    display: none;
    flex-direction: column;
    height: 100vh;
    overflow: hidden
}

.header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px
}

.header-logo {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent)
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border-radius: 20px
}

.user-name {
    font-size: 12px;
    font-weight: 600
}

.user-role {
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px
}

.user-role.admin {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent)
}

.user-role.editor {
    background: rgba(63, 185, 80, 0.15);
    color: var(--success)
}

.user-role.viewer {
    background: rgba(139, 148, 158, 0.15);
    color: var(--text-secondary)
}

/* ─── Toolbar ─────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    height: var(--toolbar-height);
    padding: 0 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 3px;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden
}

.toolbar::-webkit-scrollbar {
    height: 3px
}

.toolbar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px
}

.toolbar .divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0
}

.toolbar select {
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 11px;
    outline: none;
    cursor: pointer;
    min-width: 50px;
    max-width: 130px
}

.toolbar select:focus {
    border-color: var(--accent)
}

.btn-icon {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
    flex-shrink: 0
}

.btn-icon:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border)
}

.btn-icon.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent)
}

.color-btn {
    position: relative
}

.color-indicator {
    width: 16px;
    height: 3px;
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 1px
}

/* ─── Formula Bar ─────────────────── */
.formula-bar {
    display: flex;
    align-items: center;
    height: var(--formula-bar-height);
    padding: 0 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0
}

.cell-reference {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    min-width: 60px;
    text-align: center;
    color: var(--accent)
}

.formula-icon {
    padding: 0 8px;
    color: var(--text-muted);
    font-style: italic;
    font-weight: 600;
    font-size: 12px
}

.formula-input {
    flex: 1;
    padding: 4px 10px;
    background: var(--bg-cell);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
    height: 26px
}

.formula-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow)
}

/* ─── Grid ────────────────────────── */
.grid-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative
}

.grid-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative
}

.grid-container::-webkit-scrollbar {
    width: 10px;
    height: 10px
}

.grid-container::-webkit-scrollbar-track {
    background: var(--bg-primary)
}

.grid-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
    border: 2px solid var(--bg-primary)
}

.grid-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted)
}

.grid-container::-webkit-scrollbar-corner {
    background: var(--bg-primary)
}

.grid-table {
    border-collapse: collapse;
    table-layout: fixed;
    border-spacing: 0
}

/* Headers */
.corner {
    width: var(--row-header-width);
    min-width: var(--row-header-width);
    height: 26px;
    background: var(--grid-header-bg);
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    position: sticky;
    top: 0;
    left: 0;
    z-index: 15;
    cursor: pointer
}

.corner:hover {
    background: var(--bg-header-hover)
}

.col-header {
    height: 26px;
    background: var(--grid-header-bg);
    color: var(--grid-header-text);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    position: sticky;
    top: 0;
    z-index: 10;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    padding: 0 4px
}

.col-header:hover {
    background: var(--bg-header-hover);
    color: var(--text-primary)
}

.col-header.selected {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 700
}

.col-header.frozen-col {
    border-right: 3px solid var(--accent) !important;
    background: var(--accent-dim)
}

.col-num {
    font-size: 8px;
    color: var(--text-muted);
    vertical-align: sub;
    margin-left: 1px;
    font-weight: 400
}

.col-resize-handle {
    position: absolute;
    right: -3px;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 11
}

.col-resize-handle:hover,
.col-resize-handle.resizing {
    background: var(--accent);
    opacity: .5
}

.row-header {
    width: var(--row-header-width);
    min-width: var(--row-header-width);
    background: var(--grid-header-bg);
    color: var(--grid-header-text);
    font-size: 11px;
    text-align: center;
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    position: sticky;
    left: 0;
    z-index: 5;
    cursor: pointer;
    user-select: none
}

.row-header:hover {
    background: var(--bg-header-hover);
    color: var(--text-primary)
}

.row-header.selected {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 700
}

.row-resize-handle {
    position: absolute;
    bottom: -3px;
    left: 0;
    right: 0;
    height: 6px;
    cursor: row-resize;
    z-index: 6
}

.row-resize-handle:hover,
.row-resize-handle.resizing {
    background: var(--accent);
    opacity: .5
}

/* Frozen rows */
tr.frozen-row {
    position: sticky;
    z-index: 8
}

tr.frozen-row td,
tr.frozen-row .row-header {
    border-bottom: 3px solid var(--accent) !important
}

/* Cells */
.cell {
    padding: 0;
    border-right: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
    position: relative;
    overflow: hidden
}

.cell:hover {
    background: var(--bg-cell-hover)
}

.cell.selected {
    background: var(--bg-cell-selected) !important;
    outline: 2px solid var(--grid-selection-border);
    outline-offset: -2px;
    z-index: 3
}

.cell.in-range {
    background: var(--grid-selection)
}

.cell.editing {
    overflow: visible;
    z-index: 20
}

.cell.locked {
    background: var(--lock-bg)
}

.cell.locked::after {
    content: '🔒';
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: 8px;
    opacity: .5
}

.cell-content {
    padding: 2px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 100%;
    display: flex;
    align-items: center;
    line-height: 1.3
}

.cell-editor {
    position: absolute;
    inset: 0;
    padding: 2px 6px;
    background: var(--bg-cell);
    color: var(--text-primary);
    border: 2px solid var(--accent);
    font-family: var(--font-family);
    font-size: 13px;
    outline: none;
    resize: none;
    z-index: 21;
    min-width: 150px;
    min-height: 100%
}

/* Ref highlights */
.ref-highlight-1 {
    box-shadow: inset 0 0 0 2px var(--ref-color-1) !important
}

.ref-highlight-2 {
    box-shadow: inset 0 0 0 2px var(--ref-color-2) !important
}

.ref-highlight-3 {
    box-shadow: inset 0 0 0 2px var(--ref-color-3) !important
}

.ref-highlight-4 {
    box-shadow: inset 0 0 0 2px var(--ref-color-4) !important
}

.ref-highlight-5 {
    box-shadow: inset 0 0 0 2px var(--ref-color-5) !important
}

.ref-highlight-6 {
    box-shadow: inset 0 0 0 2px var(--ref-color-6) !important
}

.ref-highlight-7 {
    box-shadow: inset 0 0 0 2px var(--ref-color-7) !important
}

.ref-highlight-8 {
    box-shadow: inset 0 0 0 2px var(--ref-color-8) !important
}

/* ─── Sheet Tabs ──────────────────── */
.sheet-tabs {
    display: flex;
    align-items: center;
    height: var(--sheet-tabs-height);
    padding: 0 8px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    gap: 2px;
    flex-shrink: 0;
    overflow-x: auto
}

.sheet-tabs::-webkit-scrollbar {
    height: 3px
}

.sheet-tab-add {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    margin-right: 6px;
    transition: all var(--transition-fast);
    flex-shrink: 0
}

.sheet-tab-add:hover {
    background: var(--bg-elevated);
    color: var(--accent);
    border-color: var(--accent)
}

.sheet-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    height: 28px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: all var(--transition-fast);
    position: relative;
    flex-shrink: 0
}

.sheet-tab:hover {
    background: var(--bg-elevated);
    color: var(--text-primary)
}

.sheet-tab.active {
    background: var(--bg-cell);
    color: var(--text-primary);
    border-bottom-color: var(--bg-cell);
    font-weight: 600
}

.sheet-tab.hidden-sheet {
    opacity: .5;
    font-style: italic
}

.sheet-tab .tab-color-strip {
    position: absolute;
    bottom: 0;
    left: 4px;
    right: 4px;
    height: 3px;
    border-radius: 2px 2px 0 0
}

.sheet-tab-name {
    outline: none;
    min-width: 20px
}

.sheet-tab-name[contenteditable="true"] {
    background: var(--bg-cell);
    padding: 0 4px;
    border-radius: 2px
}

/* ─── Context Menu ────────────────── */
.context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 0;
    min-width: 200px;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: ctxFadeIn .12s ease
}

.context-menu .ctx-submenu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 0;
    min-width: 160px;
    box-shadow: var(--shadow-lg);
    z-index: 1001
}

@keyframes ctxFadeIn {
    from {
        opacity: 0;
        transform: scale(.95)
    }

    to {
        opacity: 1;
        transform: scale(1)
    }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast)
}

.ctx-item:hover {
    background: var(--bg-elevated)
}

.ctx-item .ctx-shortcut {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 11px
}

.ctx-item.danger {
    color: var(--danger)
}

.ctx-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0
}

/* ─── Modals ──────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    animation: modalFadeIn .2s ease
}

@keyframes modalFadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 520px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: modalSlideIn .25s ease
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border)
}

.modal-header h2 {
    font-size: 15px;
    font-weight: 600
}

.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast)
}

.modal-close:hover {
    background: rgba(248, 81, 73, 0.15);
    color: var(--danger)
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border)
}

.modal-table {
    width: 100%;
    border-collapse: collapse
}

.modal-table th {
    text-align: left;
    padding: 8px 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border)
}

.modal-table td {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-subtle)
}

.modal-table tr:hover td {
    background: var(--bg-tertiary)
}

.modal-table .actions {
    display: flex;
    gap: 4px
}

/* Function picker */
.func-cat-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--accent);
    padding: 8px 4px 4px;
    border-bottom: 1px solid var(--border-subtle)
}

.func-item {
    padding: 6px 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast)
}

.func-item:hover {
    background: var(--bg-elevated)
}

/* ─── Tooltips ────────────────────── */
[data-tooltip] {
    position: relative
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 500
}

[data-tooltip]:hover::after {
    opacity: 1
}

/* ─── Formula Hint Box ────────────── */
.formula-hint-box {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 0;
    min-width: 260px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    display: none
}

.formula-hint-item {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    transition: background var(--transition-fast)
}

.formula-hint-item:hover {
    background: var(--bg-elevated)
}

.formula-hint-item b {
    color: var(--accent)
}

.hint-ru {
    font-size: 11px;
    color: var(--text-muted)
}

.hint-desc {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 2px
}

/* ─── Status Bar ──────────────────── */
.status-bar {
    display: flex;
    align-items: center;
    height: 24px;
    padding: 0 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    gap: 16px;
    flex-shrink: 0
}

.status-bar .status-item {
    display: flex;
    align-items: center;
    gap: 4px
}

.status-bar .status-value {
    color: var(--text-secondary)
}

/* ─── Toasts ──────────────────────── */
.toast-container {
    position: fixed;
    bottom: 60px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000
}

.toast {
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 12px;
    box-shadow: var(--shadow-md);
    animation: toastIn .3s ease;
    max-width: 320px
}

.toast.error {
    border-color: rgba(248, 81, 73, 0.4);
    background: rgba(248, 81, 73, 0.1)
}

.toast.success {
    border-color: rgba(63, 185, 80, 0.4);
    background: rgba(63, 185, 80, 0.1)
}

.toast.info {
    border-color: rgba(88, 166, 255, 0.4);
    background: rgba(88, 166, 255, 0.1)
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px)
    }

    to {
        opacity: 1;
        transform: translateX(0)
    }
}

/* ─── Color Picker (styled) ───────── */
.storm-color-picker {
    position: fixed;
    background: var(--picker-bg);
    border: 1px solid var(--picker-border);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    width: 248px;
    animation: ctxFadeIn .15s ease
}

.picker-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-align: center
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    margin-bottom: 10px
}

.picker-swatch {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--transition-fast)
}

.picker-swatch:hover {
    transform: scale(1.2);
    border-color: var(--text-primary);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
    z-index: 2
}

.picker-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary)
}

.picker-custom input[type=color] {
    width: 28px;
    height: 24px;
    border: none;
    cursor: pointer;
    background: transparent
}

/* ─── Border Picker ───────────────── */
.storm-border-picker {
    position: fixed;
    background: var(--picker-bg);
    border: 1px solid var(--picker-border);
    border-radius: var(--radius-md);
    padding: 4px 0;
    min-width: 220px;
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    animation: ctxFadeIn .15s ease
}

/* ─── Collaborative Editing ───────── */
.collab-users {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px
}

.collab-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    border: 2px solid var(--bg-secondary);
    cursor: default;
    position: relative;
    transition: transform var(--transition-fast)
}

.collab-avatar:hover {
    transform: scale(1.15);
    z-index: 10
}

.collab-avatar[data-tooltip]::after {
    bottom: calc(100% + 6px)
}

.collab-cursor {
    position: absolute;
    width: 2px;
    height: 100%;
    z-index: 18;
    pointer-events: none;
    animation: cursorBlink 1.2s infinite
}

.collab-cursor-label {
    position: absolute;
    top: -16px;
    left: 0;
    padding: 1px 5px;
    border-radius: 2px;
    font-size: 9px;
    color: #fff;
    white-space: nowrap;
    font-weight: 600
}

@keyframes cursorBlink {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .3
    }
}

.collab-cell-highlight {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 2px solid;
    border-radius: 1px;
    opacity: .6
}

/* ─── Filters ─────────────────────── */
.filter-icon {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    color: var(--text-muted);
    background: var(--grid-header-bg);
    border-radius: 2px;
    z-index: 11
}

.filter-icon:hover {
    color: var(--accent);
    background: var(--accent-dim)
}

.filter-dropdown {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    min-width: 240px;
    max-height: 340px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 1002
}

.filter-dropdown .filter-search {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 12px;
    outline: none;
    margin-bottom: 8px
}

.filter-dropdown .filter-search:focus {
    border-color: var(--accent)
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 4px;
    font-size: 12px;
    cursor: pointer;
    border-radius: var(--radius-sm)
}

.filter-option:hover {
    background: var(--bg-elevated)
}

.filter-option input[type=checkbox] {
    accent-color: var(--accent)
}

.filter-actions {
    display: flex;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px
}

.temp-filter-bar {
    display: flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    background: rgba(88, 166, 255, 0.08);
    border-bottom: 1px solid var(--accent-dim);
    font-size: 11px;
    color: var(--accent);
    gap: 8px;
    flex-shrink: 0
}

.temp-filter-bar button {
    background: transparent;
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    color: var(--accent);
    padding: 2px 8px;
    font-size: 10px;
    cursor: pointer;
    font-family: var(--font-family)
}

.temp-filter-bar button:hover {
    background: var(--accent-dim)
}

/* ─── Online Users ────────────────── */
.online-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    background: rgba(63, 185, 80, 0.1);
    border: 1px solid rgba(63, 185, 80, 0.25);
    border-radius: 20px;
    font-size: 11px;
    color: var(--success)
}

.online-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: onlinePulse 2s infinite
}

@keyframes onlinePulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1)
    }

    50% {
        opacity: .5;
        transform: scale(.8)
    }
}

/* ─── Spinner ─────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

/* ─── Print ───────────────────────── */
@media print {

    .header,
    .toolbar,
    .formula-bar,
    .sheet-tabs,
    .status-bar,
    .toast-container {
        display: none !important
    }

    .main-app {
        display: block !important
    }

    .grid-wrapper {
        overflow: visible !important
    }

    .grid-container {
        overflow: visible !important;
        transform: none !important
    }

    .cell {
        border: 1px solid #ccc !important
    }
}