/* ── Inriz Calc ──────────────────────────────────────────── */

:root {
    --bg: #141414;
    --bg-surface: #1c1c1c;
    --bg-sidebar: #181818;
    --bg-hover: #242424;
    --bg-active: #2a2a2a;
    --bg-input: #111;
    --border: #2a2a2a;
    --border-subtle: #222;
    --text: #e8e8e8;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #4a90d9;
    --accent-hover: #5a9ee6;
    --danger: #d94a4a;
    --success: #4a9;
    --warning: #c90;

    /* syntax */
    --hl-default: #d4d4d4;
    --hl-number: #b5cea8;
    --hl-constant: #d7a0a0;
    --hl-function: #dcdcaa;
    --hl-variable: #9cdcfe;
    --hl-comment: #6a9955;
    --hl-highlight: rgba(255, 255, 255, 0.06);

    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', system-ui, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
    --sidebar-w: 240px;
    --toolbar-h: 36px;
    --menubar-h: 28px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────── */

.app-shell { display: flex; flex-direction: column; height: 100vh; }

/* ── Toolbar ─────────────────────────────────────────────── */

.toolbar {
    height: var(--toolbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
    z-index: 20;
    user-select: none;
}

.toolbar .brand {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 8px;
    border-right: 1px solid var(--border);
    margin-right: 4px;
}

.toolbar .brand img { height: 18px; opacity: 0.85; }
.toolbar .brand span { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: -0.2px; }

.toolbar .doc-name {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    background: none;
    border: none;
    outline: none;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-ui);
    min-width: 80px;
    max-width: 200px;
}

.toolbar .doc-name:hover, .toolbar .doc-name:focus { background: var(--bg-hover); }

.toolbar .save-badge {
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 3px;
    font-weight: 500;
    line-height: 18px;
}
.toolbar .save-badge.saved   { color: var(--success); background: rgba(68, 170, 153, 0.1); }
.toolbar .save-badge.saving  { color: var(--accent); background: rgba(74, 144, 217, 0.1); }
.toolbar .save-badge.unsaved { color: var(--warning); background: rgba(204, 153, 0, 0.1); }

.toolbar .spacer { flex: 1; }

.account-area { position: relative; }

.toolbar .account-btn {
    font-size: 12px;
    color: var(--text-secondary);
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 10px;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: background 0.1s;
}
.toolbar .account-btn:hover { background: var(--bg-hover); color: var(--text); }

.account-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 160px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
}

.account-user {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}

.account-sep { height: 1px; background: var(--border); margin: 2px 0; }

.account-item {
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.08s;
}
.account-item:hover { background: var(--bg-hover); color: var(--text); }

/* ── Menu bar ────────────────────────────────────────────── */

.menubar {
    height: var(--menubar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 0;
    flex-shrink: 0;
    z-index: 15;
    user-select: none;
}

.menu-trigger {
    position: relative;
    font-size: 12px;
    color: var(--text-secondary);
    background: none;
    border: none;
    padding: 3px 10px;
    cursor: pointer;
    border-radius: 3px;
    font-family: var(--font-ui);
    transition: background 0.1s, color 0.1s;
}
.menu-trigger:hover, .menu-trigger.open { background: var(--bg-hover); color: var(--text); }

.menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.08s;
    gap: 8px;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item.disabled { color: var(--text-muted); pointer-events: none; }

.menu-item .shortcut {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-ui);
}

.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Body ────────────────────────────────────────────────── */

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

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header .btn-new {
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px dashed var(--border);
    border-radius: 4px;
    font-family: var(--font-ui);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.sidebar-header .btn-new:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

.sidebar-list { flex: 1; overflow-y: auto; padding: 4px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.calc-item {
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.08s;
    display: flex;
    flex-direction: column;
    gap: 1px;
    position: relative;
}
.calc-item:hover { background: var(--bg-hover); }
.calc-item.active { background: var(--bg-active); }

.calc-item .calc-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 20px;
}

.calc-item .calc-time { font-size: 10px; color: var(--text-muted); }

.calc-item .calc-actions {
    position: absolute;
    right: 6px;
    top: 6px;
    display: flex;
    gap: 1px;
    opacity: 0;
    transition: opacity 0.1s;
}
.calc-item:hover .calc-actions { opacity: 1; }

.calc-actions button {
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 3px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.calc-actions button:hover { background: var(--bg-hover); color: var(--text); }
.calc-actions button.delete:hover { color: var(--danger); }

.sidebar-empty {
    padding: 16px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
}

/* ── Main ────────────────────────────────────────────────── */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-wrapper {
    position: relative;
    padding: 16px 20px;
    flex: 1 1 0;
    min-height: 80px;
    overflow-y: auto;
}
.editor-wrapper::-webkit-scrollbar { width: 5px; }
.editor-wrapper::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.editor-wrapper textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    color: rgba(200, 200, 200, 0.45);
    caret-color: var(--accent);
    position: relative;
    z-index: 2;
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 4;
}

.editor-wrapper textarea::placeholder { color: var(--text-muted); }

.editor-wrapper .highlight-overlay {
    position: absolute;
    top: 16px;
    left: 20px;
    right: 20px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    pointer-events: none;
    z-index: 1;
    tab-size: 4;
}

.highlight-overlay .hl-default  { color: var(--hl-default); }
.highlight-overlay .hl-number   { color: var(--hl-number); }
.highlight-overlay .hl-constant { color: var(--hl-constant); }
.highlight-overlay .hl-function { color: var(--hl-function); }
.highlight-overlay .hl-variable { color: var(--hl-variable); }
.highlight-overlay .hl-comment  { color: var(--hl-comment); }
.highlight-overlay .hl-active   { background: var(--hl-highlight); border-radius: 2px; }

/* ── Results ─────────────────────────────────────────────── */

/* ── Divider ─────────────────────────────────────────────── */

.divider {
    height: 5px;
    background: var(--border);
    cursor: row-resize;
    flex-shrink: 0;
    position: relative;
    transition: background 0.1s;
}
.divider:hover, .divider.dragging { background: var(--accent); }
.divider::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
}

.results-panel {
    padding: 12px 20px;
    min-height: 48px;
    background: rgba(0, 0, 0, 0.2);
    overflow-y: auto;
    flex-shrink: 0;
}
.results-panel::-webkit-scrollbar { width: 5px; }
.results-panel::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.editor-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.result-single { font-family: var(--font-mono); font-size: 14px; color: var(--success); padding: 2px 0; }
.result-error  { font-family: var(--font-mono); font-size: 12px; color: var(--danger); padding: 2px 0; }
.result-empty  { font-size: 12px; color: var(--text-muted); padding: 2px 0; }

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 12px;
}

.result-table th {
    text-align: left;
    padding: 4px 12px 4px 0;
    color: var(--text-muted);
    font-weight: 500;
    font-family: var(--font-ui);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.result-table td {
    padding: 3px 12px 3px 0;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
}

.result-table td:first-child  { color: var(--hl-variable); white-space: nowrap; }
.result-table td:nth-child(2) { color: var(--hl-number); }
.result-table td:nth-child(3) { color: var(--hl-comment); font-size: 11px; }

/* ── Responsive ──────────────────────────────────────────── */

/* ── Remote cursors ──────────────────────────────────────── */

.remote-cursor {
    position: relative;
    border-left: 2px solid;
    margin-left: -1px;
    margin-right: -1px;
    animation: cursorBlink 1.2s step-end infinite;
}

.remote-cursor-label {
    position: absolute;
    bottom: 100%;
    left: -1px;
    font-size: 9px;
    font-family: var(--font-ui);
    color: #fff;
    padding: 1px 4px;
    border-radius: 2px 2px 2px 0;
    white-space: nowrap;
    pointer-events: none;
    line-height: 1.3;
}

@keyframes cursorBlink {
    50% { opacity: 0.4; }
}

/* ── Collaborator dots ───────────────────────────────────── */

.collab-indicator {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: 8px;
}

.collab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    cursor: default;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 700px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: calc(var(--toolbar-h) + var(--menubar-h));
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.15s ease;
    }
    .sidebar.open { transform: translateX(0); }
}
