:root {
    --bg: #FAFAF7;
    --border: #E5E2DB;
    --header-bg: #F2EFE8;
    --hover-bg: #F2EFE8;
    --index-hover-bg: #E0D8C6;
    --selected-bg: #F5E6D8;
    --selected-strong: #EAD4BB;
    --text: #1A1A1A;
    --muted: #6B6B6B;
    --accent: #A0522D;
    --accent-dark: #8B4513;

}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    flex: 0 0 auto;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.toolbar button,
.tool-link {
    font: inherit;
    font-size: 13px;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    text-decoration: none;
}

.toolbar button:hover,
.tool-link:hover {
    background: var(--header-bg);
    color: var(--text);
}

.toolbar button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.tool-link[hidden] {
    display: none;
}

.hint {
    color: var(--muted);
    font-size: 13px;
}

.msg {
    flex: 0 0 auto;
    padding: 6px 12px;
    color: var(--muted);
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    white-space: nowrap;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
}

th, td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    text-align: left;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--header-bg);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
}

thead th:hover {
    background: var(--index-hover-bg);
}

thead th .arrow {
    display: inline-block;
    width: 1em;
    text-align: center;
    color: var(--accent);
    font-size: 11px;
    margin-left: 4px;
}

.rownum {
    text-align: right;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    background: var(--header-bg);
    font-variant-numeric: tabular-nums;
}

thead .rownum {
    z-index: 4;
}

@media (hover: hover) {
    tbody tr:not(.selected):hover td:not(.rownum) {
        background: var(--hover-bg);
    }
    tbody td.rownum:hover {
        background: var(--index-hover-bg);
    }
}

tbody tr.selected td {
    background: var(--selected-bg);
}

tbody tr.selected td.rownum {
    background: var(--selected-strong);
    color: var(--text);
}

table.sticky-first .col-sticky {
    position: sticky;
    left: var(--rownum-w, 48px);
    z-index: 2;
}

table.sticky-first tbody .col-sticky {
    background: var(--bg);
}

table.sticky-first thead .col-sticky {
    z-index: 5;
}

@media (hover: hover) {
    table.sticky-first tbody tr:hover .col-sticky {
        background: var(--hover-bg);
    }
}

table.sticky-first tbody tr.selected .col-sticky {
    background: var(--selected-bg);
}

.rownum {
    position: sticky;
    left: 0;
    z-index: 2;
}

thead .rownum {
    z-index: 6;
}

@media (max-width: 640px) {
    .toolbar {
        gap: 8px;
        padding: 6px 8px;
    }

    .toolbar button,
    .tool-link {
        padding: 5px 9px;
        font-size: 12px;
    }

    .hint {
        width: 100%;
        font-size: 12px;
    }

    table {
        font-size: 12px;
    }

    th, td {
        padding: 4px 8px;
    }
}
