:root {
    color-scheme: light;
    --bg: #f5f7f2;
    --panel: #ffffff;
    --panel-soft: #eef4ee;
    --ink: #17202a;
    --muted: #68737d;
    --line: #d9dfd7;
    --accent: #207a55;
    --accent-dark: #155c40;
    --warn: #9a5b16;
    --danger: #b42318;
    --focus: #d69b2d;
    --shadow: 0 18px 45px rgba(29, 41, 57, 0.12);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

button,
input {
    font: inherit;
}

a {
    color: inherit;
}

.page {
    min-height: 100vh;
    padding: 48px 20px;
}

.page-upload {
    display: grid;
    place-items: center;
}

.upload-panel {
    width: min(760px, 100%);
    padding: clamp(24px, 4vw, 44px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel-heading {
    display: grid;
    gap: 10px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    max-width: 680px;
    margin-bottom: 0;
    font-size: clamp(30px, 5vw, 52px);
    line-height: 1.04;
    font-weight: 800;
}

h2 {
    margin-bottom: 14px;
    font-size: 22px;
}

.subtext {
    max-width: 560px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.55;
}

.upload-form {
    display: grid;
    gap: 16px;
}

.file-drop {
    display: grid;
    gap: 8px;
    min-height: 150px;
    align-content: center;
    padding: 26px;
    border: 2px dashed #b8c6b9;
    border-radius: 8px;
    background: var(--panel-soft);
    cursor: pointer;
}

.file-drop:focus-within {
    outline: 3px solid rgba(214, 155, 45, 0.35);
    outline-offset: 2px;
}

.file-drop-title {
    font-size: 20px;
    font-weight: 700;
}

.file-drop-meta {
    color: var(--muted);
}

.file-drop input {
    width: 100%;
    min-width: 0;
    color: var(--muted);
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button:focus-visible {
    outline: 3px solid rgba(214, 155, 45, 0.42);
    outline-offset: 2px;
}

.button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.button-primary {
    background: var(--accent);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--accent-dark);
}

.button-secondary {
    border-color: var(--line);
    background: #ffffff;
    color: var(--ink);
}

.button-secondary:hover {
    border-color: #aebaae;
    background: #f9fbf8;
}

.notice {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 6px;
    font-weight: 650;
}

.notice-error {
    border: 1px solid rgba(180, 35, 24, 0.25);
    background: #fff3f0;
    color: var(--danger);
}

.result-panel {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.result-name {
    color: var(--muted);
}

.copy-row,
.actions-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.copy-row {
    margin-bottom: 12px;
}

.copy-row input {
    flex: 1 1 280px;
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfa;
    color: var(--ink);
}

.editor-shell {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    background: #f7f8f5;
}

.editor-topbar {
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
}

.doc-title-block {
    min-width: 0;
}

.doc-title-block h1 {
    overflow-wrap: anywhere;
    margin: 4px 0;
    font-size: clamp(20px, 3vw, 28px);
    line-height: 1.18;
}

.doc-meta-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.expiry-badge {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid rgba(154, 91, 22, 0.28);
    border-radius: 6px;
    background: #fff7e8;
    color: var(--warn);
    font-weight: 800;
}

.back-link {
    color: var(--accent);
    font-size: 13px;
    font-weight: 750;
    text-decoration: none;
}

.editor-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.sheet-nav-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    justify-content: space-between;
    min-width: 0;
    padding: 8px 22px 0;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
}

.sheet-context {
    display: flex;
    flex: 0 0 auto;
    gap: 12px;
    align-items: center;
    padding-bottom: 10px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

#status-text[data-tone="success"] {
    color: var(--accent-dark);
    font-weight: 750;
}

#status-text[data-tone="error"] {
    color: var(--danger);
    font-weight: 750;
}

.sheet-tabs {
    display: flex;
    flex: 1 1 auto;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    padding: 0;
}

.sheet-tab {
    min-height: 38px;
    max-width: 220px;
    overflow: hidden;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
    background: #f7f8f5;
    color: var(--muted);
    cursor: pointer;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet-tab[aria-selected="true"] {
    background: #ffffff;
    color: var(--ink);
    font-weight: 750;
}

.editor-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    gap: 14px;
    min-height: 0;
    overflow: hidden;
    padding: 16px 22px 22px;
}

.grid-wrap {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    min-height: 0;
}

.formula-bar {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
}

.formula-address {
    display: inline-flex;
    height: 38px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #e8efe8;
    color: #4d5963;
    font-size: 13px;
    font-weight: 800;
}

.formula-bar input {
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--ink);
}

.formula-bar input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 0;
}

.grid-scroll {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.sheet-grid {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
}

.sheet-grid th,
.sheet-grid td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.sheet-grid thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    height: 34px;
    min-width: 120px;
    background: #e8efe8;
    color: #4d5963;
    font-size: 12px;
    font-weight: 800;
}

.sheet-grid thead th:first-child,
.sheet-grid tbody th {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 54px;
    width: 54px;
    background: #e8efe8;
    color: #4d5963;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
}

.sheet-grid thead th:first-child {
    z-index: 4;
}

.sheet-grid td {
    min-width: 120px;
    width: 120px;
    height: 34px;
    padding: 0;
    background: #ffffff;
}

.sheet-grid input {
    width: 100%;
    height: 34px;
    min-width: 0;
    padding: 5px 8px;
    border: 0;
    background: transparent;
    color: var(--ink);
}

.sheet-grid input:focus {
    position: relative;
    z-index: 1;
    outline: 2px solid var(--focus);
    outline-offset: -2px;
    background: #fffdf6;
}

.empty-state {
    display: grid;
    min-height: 260px;
    place-items: center;
    color: var(--muted);
    font-weight: 700;
}

.collab-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    min-height: 0;
    overflow: hidden;
}

.online-block,
.chat-block {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.online-block {
    padding: 14px;
}

.chat-block {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 0;
    padding: 14px;
}

.collab-heading,
.chat-block h2 {
    margin: 0 0 10px;
}

.collab-heading h2,
.chat-block h2 {
    margin: 0;
    font-size: 18px;
}

.collab-heading p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.presence-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
}

.presence-list li {
    max-width: 100%;
    overflow: hidden;
    padding: 6px 10px;
    border: 1px solid #c8d8cb;
    border-radius: 999px;
    background: #eef8ef;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 2px 12px;
}

.chat-empty {
    display: grid;
    min-height: 120px;
    place-items: center;
    color: var(--muted);
    font-weight: 700;
}

.chat-message {
    display: grid;
    gap: 3px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
}

.chat-message.is-own {
    border-color: rgba(32, 122, 85, 0.28);
    background: #f1f8f3;
}

.chat-message-meta {
    display: flex;
    gap: 8px;
    align-items: baseline;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
}

.chat-message-name {
    overflow: hidden;
    color: var(--ink);
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message-body {
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.chat-form input {
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

@media (max-width: 760px) {
    .editor-shell {
        height: auto;
        overflow: visible;
    }

    .page {
        padding: 20px 12px;
    }

    .upload-panel {
        padding: 22px;
    }

    .editor-topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px;
    }

    .editor-actions {
        justify-content: stretch;
        width: 100%;
    }

    .editor-actions .button {
        flex: 1 1 150px;
    }

    .sheet-nav-row {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
        padding: 8px 14px 0;
    }

    .sheet-tabs {
        order: 2;
    }

    .sheet-context {
        justify-content: space-between;
        order: 1;
        width: 100%;
        padding-bottom: 0;
    }

    .editor-workspace {
        grid-template-columns: 1fr;
        overflow: visible;
        padding: 12px 14px 16px;
    }

    .grid-scroll {
        min-height: 500px;
    }

    .collab-panel {
        min-height: 460px;
        overflow: visible;
    }

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