/*
 * QuroGrid 기본 스타일.
 * 테마 (GS-080·GS-081): 앱은 --quro-* 변수를 그리드나 그 바깥 요소(body 등)에 두어 색을 바꾼다.
 * 두지 않으면 아래 기본값을 쓴다 (다크 모드는 앱이 다크 값의 토큰을 둔다, A-67).
 * 그리드 안에서는 풀어 둔 --qg-*만 쓴다. 색 기본값은 아래 정의에만 둔다.
 * 선택·오류·경고 배경은 강조색을 배경에 섞어 만들어 밝은·다크 모드 모두 글자가 읽힌다.
 */
/* The frame too: the scroll buttons sit in it, outside the grid (GS-101) */
.quro-grid-frame,
.quro-grid {
    --qg-bg: var(--quro-bg, #fff);
    --qg-text: var(--quro-text, #1d2330);
    --qg-border: var(--quro-border, #d0d5dd);
    --qg-head-bg: var(--quro-head-bg, #f2f4f7);
    --qg-active: var(--quro-active, #2e6be6);
    --qg-selected: var(--quro-selected, color-mix(in srgb, var(--qg-active) 16%, var(--qg-bg)));
    --qg-error-line: var(--quro-error-line, #d92d20);
    --qg-error: var(--quro-error, color-mix(in srgb, var(--qg-error-line) 12%, var(--qg-bg)));
    --qg-warning-line: var(--quro-warning-line, #f79009);
    --qg-warning: var(--quro-warning, color-mix(in srgb, var(--qg-warning-line) 14%, var(--qg-bg)));
    --qg-check-line: var(--quro-check-line, #667085);
    --qg-check-mark: var(--quro-check-mark, #fff);
    --qg-shadow: var(--quro-shadow, rgb(0 0 0 / 16%));
    --qg-tone-danger: var(--quro-tone-danger, var(--qg-error-line));
    --qg-tone-success: var(--quro-tone-success, #079455);
    --qg-row-state-inserted: var(--quro-row-state-inserted, var(--qg-tone-success));
    --qg-row-state-updated: var(--quro-row-state-updated, var(--qg-active));
    --qg-row-state-deleted: var(--quro-row-state-deleted, var(--qg-error-line));
    --qg-tone-muted: var(--quro-tone-muted, var(--qg-check-line));
    --qg-tone-highlight: var(--quro-tone-highlight, color-mix(in srgb, var(--qg-warning-line) 18%, var(--qg-bg)));
    --qg-label: var(--quro-label, #5b6475);   /* Label cell text, same token as QuroLabel */
    --qg-readonly-bg: var(--quro-readonly-bg, color-mix(in srgb, var(--qg-check-line) 14%, var(--qg-bg)));   /* locked row (RowReadOnly) */
    --qg-row-height: var(--quro-row-height, 28px);   /* layout value the grid sets from RowHeight (not a color) */
}

.quro-grid {
    display: inline-block;
    box-sizing: border-box;
    overflow: auto;
    max-width: 100%;
    scroll-padding-left: calc(var(--qg-row-number-width, 0px) + var(--qg-row-state-width, 0px));   /* keyboard scrolling stops clear of the sticky number and state columns */
    border: 1px solid var(--qg-border);
    background: var(--qg-bg);
    color: var(--qg-text);
}

/* Frame around the grid (GS-101). Without scroll buttons it has no box of its own */
.quro-grid-frame {
    display: contents;
}

.quro-grid-frame[data-scroll-buttons] {
    display: inline-block;
    position: relative;
    max-width: 100%;
    vertical-align: top;
}

.quro-grid-frame[data-scroll-buttons] > .quro-grid {
    display: block;
}

/* Scroll buttons (GS-101): quro-grid.js sets data-visible where the grid can scroll further, and the scrollbar sizes on the frame */
.quro-scroll-button {
    display: none;
    position: absolute;
    z-index: 3;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--qg-border);
    border-radius: 3px;
    background: var(--qg-head-bg);
    color: var(--qg-text);
    font-size: 10px;
    line-height: 20px;
    text-align: center;
    opacity: 0.85;
    cursor: pointer;
}

.quro-scroll-button[data-visible] {
    display: block;
}

.quro-scroll-button:hover {
    opacity: 1;
}

.quro-scroll-button[data-scroll="up"],
.quro-scroll-button[data-scroll="down"] {
    right: calc(var(--qg-scrollbar-y, 0px) + 3px);
    top: 50%;
}

.quro-scroll-button[data-scroll="up"] { transform: translateY(-24px); }
.quro-scroll-button[data-scroll="down"] { transform: translateY(2px); }
.quro-scroll-button[data-scroll="up"]::before { content: "\25B2"; }
.quro-scroll-button[data-scroll="down"]::before { content: "\25BC"; }

.quro-scroll-button[data-scroll="left"],
.quro-scroll-button[data-scroll="right"] {
    bottom: calc(var(--qg-scrollbar-x, 0px) + 3px);
    left: 50%;
}

.quro-scroll-button[data-scroll="left"] { transform: translateX(-24px); }
.quro-scroll-button[data-scroll="right"] { transform: translateX(2px); }
.quro-scroll-button[data-scroll="left"]::before { content: "\25C0"; }
.quro-scroll-button[data-scroll="right"]::before { content: "\25B6"; }

.quro-row {
    display: flex;
    width: max-content;   /* as wide as its cells: a sticky cell cannot leave its row, so a narrower row lets frozen cells scroll away */
}

/* 드래그 범위 선택 중 글자 선택이 생기지 않도록 */
.quro-body {
    user-select: none;
}

.quro-cell {
    box-sizing: border-box;
    flex: none;
    padding: 2px 6px;
    border-right: 1px solid var(--qg-border);
    border-bottom: 1px solid var(--qg-border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: inherit;
}

.quro-header,
.quro-footer {
    background: var(--qg-head-bg);
    font-weight: 600;
}

/* A blank cell has no line of text, so a footer of blank cells would collapse. A zero-width character keeps its height (GS-112) */
.quro-footer::before {
    content: "\200b";
}

.quro-head {
    position: sticky;
    top: 0;
    z-index: 2;
}

.quro-frozen {
    position: sticky;
    z-index: 1;
    background: var(--qg-bg);
}

.quro-header.quro-frozen,
.quro-footer.quro-frozen {
    background: var(--qg-head-bg);
}

/* Locked row (RowReadOnly, GS-099). :where keeps the specificity of one class: after .quro-frozen so frozen cells are grey too,
   before the tones and marks so Highlight, errors and warnings still show */
:where(.quro-row-readonly) .quro-cell {
    background: var(--qg-readonly-bg);
}

/* Default cell alignment (GS-102): the grid picks by column type, or QuroColumn.Align. Left has no class */
.quro-align-right { text-align: right; }
.quro-align-center { text-align: center; }

/* Vertical alignment (GS-109, QuroColumn.VAlign). align-content keeps the cell a block, so the ellipsis and text-align still work.
   A browser without it leaves the content at the top. Top has no class */
.quro-valign-middle { align-content: center; }
.quro-valign-bottom { align-content: end; }

/* Row number column (ShowRowNumbers, GS-100). The width variable is set on the root by the grid.
   After the read-only rule with the same specificity: the gutter stays the header color on a locked row */
.quro-row-number {
    left: 0;
    width: var(--qg-row-number-width);
    background: var(--qg-head-bg);
    color: var(--qg-label);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Row state column (ShowRowState, GS-106). The symbol is CSS only: the cell holds no text */
.quro-row-state {
    left: var(--qg-row-number-width, 0px);
    width: var(--qg-row-state-width);
    padding: 2px 0;
    background: var(--qg-head-bg);
    text-align: center;
}

.quro-row-state[data-state=inserted] { color: var(--qg-row-state-inserted); }
.quro-row-state[data-state=updated] { color: var(--qg-row-state-updated); }
.quro-row-state[data-state=deleted] { color: var(--qg-row-state-deleted); }
.quro-row-state[data-state=inserted]::before { content: "+"; }
.quro-row-state[data-state=updated]::before { content: "\25CF"; }
.quro-row-state[data-state=deleted]::before { content: "\2212"; }

/* CellStyle tones (A-59). Before the marks so an error or warning background wins over Highlight */
/* Label cell (A-56): static text, read-only like Text; only the look differs.
   Kept before the tone rules with the same specificity, so CellStyle tones win */
[data-type="label"] { color: var(--qg-label); }

.quro-tone-danger { color: var(--qg-tone-danger); }
.quro-tone-success { color: var(--qg-tone-success); }
.quro-tone-muted { color: var(--qg-tone-muted); }
.quro-tone-highlight { background: var(--qg-tone-highlight); }
.quro-tone-bold { font-weight: 600; }

/* MergeRepeated (GS-110). The text stays in the cell for copy, editors and screen readers. Two classes so it beats a tone's color;
   the active cell and a selected range have aria-selected and show their value */
.quro-cell.quro-merge-repeat:not([aria-selected=true]) { color: transparent; }
.quro-merge-repeat .quro-editor { color: var(--qg-text); }
.quro-cell.quro-merge-continues { border-bottom-color: transparent; }

.quro-mark-error {
    background: var(--qg-error);
    box-shadow: inset 0 0 0 1px var(--qg-error-line);
}

.quro-mark-warning {
    background: var(--qg-warning);
    box-shadow: inset 0 0 0 1px var(--qg-warning-line);
}

.quro-deleted .quro-cell {
    text-decoration: line-through;
    opacity: 0.6;
}

/* a frozen cell must stay opaque or the cells scrolled under it show through: it fades by color instead */
.quro-deleted .quro-frozen:not(.quro-row-state) {
    opacity: 1;
    color: color-mix(in srgb, var(--qg-text) 60%, var(--qg-bg));
}

/* the row fades, its state mark does not (GS-106) */
.quro-deleted .quro-row-state {
    text-decoration: none;
    opacity: 1;
}

/* 서버측 페이징 (A-24): 가상 스크롤은 행 높이가 일정해야 한다. 합계 행은 아래에 붙여 둔다 */
.quro-paged .quro-body .quro-row {
    height: var(--quro-row-height, 28px);
}

.quro-foot {
    position: sticky;
    bottom: 0;
    z-index: 2;
}

/* 다단 헤더 (GS-070): 그룹 칸은 가운데 정렬. 그룹이 없는 컬럼 위 빈 칸은 아래 선을 지워 컬럼 헤더와 이어 보이게 */
.quro-group-row .quro-cell {
    background: var(--qg-head-bg);
    font-weight: 600;
}

.quro-group-header {
    text-align: center;
}

.quro-group-empty {
    border-bottom-color: transparent;
}

/* 헤더: 클릭 정렬(▲▼, 다중이면 순번), 오른쪽 경계 드래그 리사이즈 (A-22·A-23) */
.quro-header {
    cursor: pointer;
    user-select: none;
}

.quro-header:not(.quro-frozen) {
    position: relative;
}

.quro-sort::after {
    margin-left: 4px;
    font-size: 0.75em;
    content: "\25B2" attr(data-order);
}

.quro-sort[data-dir=desc]::after {
    content: "\25BC" attr(data-order);
}

.quro-resize {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
}

/* 그리드가 직접 띄우는 안내 (R7): 연결 끊김 중 입력 잠금, 회로 소멸 후 변경 유실 */
.quro-notice {
    display: none;
    position: sticky;
    left: 0;
    z-index: 4;
    padding: 4px 8px;
    border-bottom: 1px solid var(--qg-warning-line);
    background: var(--qg-warning);
    white-space: normal;
}

.quro-notice-unsaved {
    display: none;
    font-weight: 600;
}

.quro-grid[data-offline] .quro-notice-offline,
.quro-grid[data-lost] .quro-notice-lost {
    display: block;
}

.quro-grid[data-offline][data-dirty] .quro-notice-unsaved {
    display: inline;
}

.quro-notice-lost {
    cursor: pointer;
}

/* 입력 잠금 중 */
.quro-grid[data-offline] .quro-body {
    opacity: 0.6;
}

/* 선택 목록 (Date 달력·Combo 목록, Addendum A-17): 그리드 스크롤 영역에 잘리지 않도록 화면 기준으로 띄운다.
   위치(top·left)는 quro-grid.js가 셀 좌표로 정한다. */
.quro-picker {
    position: fixed;
    text-align: left;   /* the list is not the cell: a centered Combo cell keeps a left list */
    z-index: 1400;
    min-width: 160px;
    background: var(--qg-bg);
    border: 1px solid var(--qg-border);
    box-shadow: 0 4px 12px var(--qg-shadow);
    white-space: normal;
}

/* 달력 (A-67): quro-grid.js가 .quro-calendar 안에 그린다 */
.quro-calendar {
    padding: 6px;
    user-select: none;
}

.quro-cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.quro-cal-title {
    font-weight: 600;
}

.quro-cal-days {
    display: grid;
    grid-template-columns: repeat(7, 32px);
    gap: 2px;
}

.quro-cal-dow {
    text-align: center;
    font-size: 0.85em;
    color: var(--qg-check-line);
}

.quro-cal-nav,
.quro-cal-day {
    height: 28px;
    min-width: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.quro-cal-nav:hover,
.quro-cal-day:hover,
.quro-option:hover {
    background: var(--qg-selected);
}

.quro-cal-day[data-outside] {
    opacity: 0.5;
}

.quro-cal-day[data-today] {
    border-color: var(--qg-active);
}

/* 키보드 강조 (GS-091) */
.quro-cal-day[data-active],
.quro-option[data-active] {
    outline: 2px solid var(--qg-active);
    outline-offset: -2px;
}

.quro-cal-day[aria-selected=true] {
    background: var(--qg-active);
    color: var(--qg-check-mark);
}

/* Combo 목록 */
.quro-options {
    margin: 0;
    padding: 4px 0;
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
}

.quro-option {
    padding: 4px 10px;
    cursor: pointer;
}

.quro-option[aria-selected=true] {
    background: var(--qg-selected);
    font-weight: 600;
}

/* Check 셀: 셀 안 체크 표시 (클릭·Space로 토글) */
.quro-check {
    display: inline-block;
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    vertical-align: middle;
    border: 1px solid var(--qg-check-line);
    border-radius: 2px;
    background: var(--qg-bg);
    cursor: pointer;
}

.quro-check[aria-checked="true"] {
    border-color: var(--qg-active);
    background: var(--qg-active);
}

.quro-check[aria-checked="true"]::after {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background: var(--qg-check-mark);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-4.9' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") center / 12px no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-4.9' fill='none' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E") center / 12px no-repeat;
}

/* Button 셀 */
.quro-button {
    display: inline-block;
    padding: 0 8px;
    border: 1px solid var(--qg-border);
    border-radius: 3px;
    background: var(--qg-head-bg);
    cursor: pointer;
}

.quro-image {
    /* fits the row height and keeps the aspect ratio (A-56) */
    display: inline-block;
    max-width: 100%;
    height: calc(var(--qg-row-height) - 6px);
    object-fit: contain;
    vertical-align: middle;
    cursor: pointer;
}

.quro-editor {
    box-sizing: border-box;
    text-align: inherit;   /* the editor sits where the value is (GS-102) */
    width: 100%;
    border: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    background: transparent;
    outline: none;
}

/* EditOnSelect (A-58): the browser editor covers the cell text, inside the active cell outline */
.quro-grid[data-edit-on-select] .quro-body-cell:not(.quro-frozen) {
    position: relative;
}

.quro-select-editor {
    position: absolute;
    inset: 2px;
    width: auto;
    padding: 0 4px;
    background: var(--qg-bg);
    text-align: inherit;
}

/* 헤더 필터 (A-31): 헤더 오른쪽 버튼(▽, 필터 중이면 채움 ▼) · 헤더 아래 패널 */
.quro-header:has(.quro-filter-button) {
    padding-right: 20px;
}

.quro-filter-button {
    position: absolute;
    top: 0;
    right: 6px;
    width: 14px;
    height: 100%;
    opacity: 0.45;
    cursor: pointer;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 2.5h9L7 6.5v3.5l-2-1V6.5z' fill='none' stroke='black' stroke-width='1.2'/%3E%3C/svg%3E") center / 12px no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 2.5h9L7 6.5v3.5l-2-1V6.5z' fill='none' stroke='black' stroke-width='1.2'/%3E%3C/svg%3E") center / 12px no-repeat;
}

.quro-filter-button:hover,
[data-filtered=true] > .quro-filter-button {
    opacity: 1;
}

[data-filtered=true] > .quro-filter-button {
    background: var(--qg-active);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 2.5h9L7 6.5v3.5l-2-1V6.5z' fill='black' stroke='black' stroke-width='1.2'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 2.5h9L7 6.5v3.5l-2-1V6.5z' fill='black' stroke='black' stroke-width='1.2'/%3E%3C/svg%3E");
}

.quro-filter-panel {
    position: fixed;
    z-index: 1400;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    padding: 8px;
    background: var(--qg-bg);
    color: var(--qg-text);
    border: 1px solid var(--qg-border);
    box-shadow: 0 4px 12px var(--qg-shadow);
}

.quro-filter-input {
    box-sizing: border-box;
    width: 100%;
    padding: 2px 4px;
    font: inherit;
    color: inherit;
    background: var(--qg-bg);
    border: 1px solid var(--qg-border);
}

.quro-filter-input[aria-invalid=true] {
    border-color: var(--qg-error-line);
    background: var(--qg-error);
}

.quro-filter-option {
    display: flex;
    gap: 6px;
    align-items: center;
    cursor: pointer;
}

.quro-filter-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.quro-filter-actions button {
    padding: 2px 10px;
    font: inherit;
    color: inherit;
    background: var(--qg-head-bg);
    border: 1px solid var(--qg-border);
    border-radius: 3px;
    cursor: pointer;
}

/* 그룹핑 (A-42): 그룹 머리 행은 한 칸(펼침 표시 ▾/▸ + "헤더: 값 (건수)"), 소계 행은 합계 행과 같은 모양 */
.quro-group-head-row {
    cursor: pointer;
    user-select: none;
}

.quro-group-head-cell {
    background: var(--qg-head-bg);
    font-weight: 600;
}

.quro-group-head-text {
    position: sticky;
    left: 6px;
}

.quro-group-head-text::before {
    display: inline-block;
    width: 1em;
    content: "\25BE";
}

[aria-expanded=false] .quro-group-head-text::before {
    content: "\25B8";
}

/* Tree (GS-104): the indent is padding, so the editors and the toggle share one measure. The toggle draws no text into the cell */
.quro-tree-cell {
    --qg-tree-pad: calc(6px + 1.2em * (var(--qg-tree-level, 0) + 1));
    padding-left: var(--qg-tree-pad);
}

.quro-tree-cell:not(.quro-frozen) {
    position: relative;
}

.quro-tree-toggle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--qg-tree-pad) - 1.2em);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.2em;
    cursor: pointer;
    user-select: none;
}

.quro-tree-toggle::before {
    content: "\25B8";
}

[aria-expanded=true] > .quro-tree-cell > .quro-tree-toggle::before {
    content: "\25BE";
}

.quro-tree-cell > .quro-select-editor {
    left: var(--qg-tree-pad);
    width: calc(100% - var(--qg-tree-pad));
}

.quro-subtotal {
    background: color-mix(in srgb, var(--qg-head-bg) 50%, var(--qg-bg));
    font-weight: 600;
}
