/* office-sheet - style.css */
.office-sheet-app {
    --office-sheet-accent: var(--primary, #2563eb);
    --office-sheet-accent-hover: var(--primary-hover, #1d4ed8);
    --office-sheet-line: var(--border, #e5e7eb);
    --office-sheet-txt: var(--text, #333333);
    --office-sheet-txt2: var(--text-secondary, #6b7280);
    --office-sheet-card: var(--bg-card, #ffffff);
    --office-sheet-inp: var(--bg-input, #ffffff);
    --office-sheet-btn: var(--bg-btn, #f3f4f6);
    --office-sheet-btnh: var(--bg-btn-hover, #e5e7eb);
    --office-sheet-r: var(--radius, 8px);
    --office-sheet-rs: var(--radius-sm, 4px);
    --office-sheet-head: var(--bg-sub, #f8f9fa);
    --office-sheet-head2: var(--bg-sub, #eef1f5);
    --office-sheet-selb: rgba(37, 99, 235, .14);
    --office-sheet-grid: var(--border, #d9d9d9);
    --office-sheet-mask: rgba(0, 0, 0, .45);
    --office-sheet-shadow: rgba(0, 0, 0, .18);
    --office-sheet-pmargin: 0.5in;
    --office-sheet-on: var(--text, #ffffff);

    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-family: system-ui, -apple-system, "Segoe UI", "WenQuanYi Micro Hei", sans-serif;
    font-size: 13px;
    color: var(--office-sheet-txt);
    background: var(--office-sheet-card);
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-r);
    overflow: hidden;
}
.office-sheet-app * { box-sizing: border-box; }

/* ribbon tabs */
.office-sheet-rtabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 8px 0;
    background: var(--office-sheet-head);
    border-bottom: 1px solid var(--office-sheet-line);
}
.office-sheet-tab-btn {
    padding: 6px 14px;
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    color: var(--office-sheet-txt2);
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--office-sheet-rs) var(--office-sheet-rs) 0 0;
}
.office-sheet-tab-btn.office-sheet-on {
    background: var(--office-sheet-card);
    color: var(--office-sheet-accent);
    border-color: var(--office-sheet-line);
    font-weight: 600;
}

/* ribbon */
.office-sheet-ribbon {
    display: block;
    padding: 8px 10px;
    background: var(--office-sheet-card);
    border-bottom: 1px solid var(--office-sheet-line);
}
.office-sheet-pane { display: none; }
.office-sheet-pane.office-sheet-on { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-start; }
.office-sheet-grp {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 2px 10px 4px;
    border-right: 1px solid var(--office-sheet-line);
    min-width: 0;
    min-height: 54px;
}
.office-sheet-grp:last-child { border-right: none; }
.office-sheet-glbl {
    font-size: 11px;
    color: var(--office-sheet-txt2);
    text-align: center;
    letter-spacing: .3px;
}
.office-sheet-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.office-sheet-row-w { min-width: 220px; }
.office-sheet-btn {
    padding: 4px 6px;
    min-height: 30px;
    min-width: 32px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-btn);
    color: var(--office-sheet-txt);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.office-sheet-btn:hover { background: var(--office-sheet-btnh); }
.office-sheet-btn.office-sheet-on { background: var(--office-sheet-accent); color: var(--office-sheet-on); border-color: var(--office-sheet-accent); }
.office-sheet-btn-p { background: var(--office-sheet-accent); color: var(--office-sheet-on); border-color: var(--office-sheet-accent); }
.office-sheet-btn-s { padding: 3px 8px; min-height: 24px; }

/* ---- ribbon icons + hover tooltip ---- */
.office-sheet-ic { width: 16px; height: 16px; flex: 0 0 16px; vertical-align: -3px; margin-right: 0; opacity: .9; }
.office-sheet-btn { display: inline-flex; align-items: center; justify-content: center; }
.office-sheet-btn[data-tip] { position: relative; }
.office-sheet-btn[data-tip]::after {
    content: attr(data-tip);
    position: absolute; top: calc(100% + 5px); left: 50%;
    transform: translateX(-50%);
    background: var(--office-sheet-txt, #333); color: var(--office-sheet-card, #fff);
    font-size: 12px; font-weight: 400; line-height: 1.4; letter-spacing: 0;
    padding: 4px 8px; border-radius: var(--office-sheet-rs, 6px);
    white-space: nowrap; pointer-events: none;
    opacity: 0; visibility: hidden;
    transition: opacity .12s ease;
}
.office-sheet-btn[data-tip]:hover::after { opacity: 1; visibility: visible; }

.office-sheet-lbl-btn { display: inline-block; }
.office-sheet-ico {
    width: 28px;
    height: 28px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-btn);
    color: var(--office-sheet-txt);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}
.office-sheet-ico:hover { background: var(--office-sheet-btnh); }
.office-sheet-ico.office-sheet-on { background: var(--office-sheet-accent); color: var(--office-sheet-on); border-color: var(--office-sheet-accent); }
.office-sheet-sel {
    padding: 4px 6px;
    min-height: 28px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-inp);
    color: var(--office-sheet-txt);
    font-size: 12px;
    max-width: 150px;
}
.office-sheet-sel-n { max-width: 70px; }
.office-sheet-cl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-btn);
    color: var(--office-sheet-txt);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    flex: 0 0 auto;
}
.office-sheet-cl:hover { background: var(--office-sheet-btn-hover); }
.office-sheet-cl input {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: 0;
    padding: 0;
}
.office-sheet-file { display: none; }

/* formula bar */
.office-sheet-fxbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--office-sheet-card);
    border-bottom: 1px solid var(--office-sheet-line);
}
.office-sheet-addr {
    width: 82px;
    padding: 4px 6px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-inp);
    color: var(--office-sheet-txt);
    font-size: 12px;
    text-align: center;
}
.office-sheet-fxs { font-style: italic; color: var(--office-sheet-txt2); font-size: 12px; }
.office-sheet-fx {
    flex: 1;
    min-width: 80px;
    padding: 4px 8px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-inp);
    color: var(--office-sheet-txt);
    font-size: 12px;
    font-family: ui-monospace, Consolas, monospace;
}

/* grid */
.office-sheet-grid {
    position: relative;
    overflow: auto;
    max-height: 430px;
    background: var(--office-sheet-card);
    outline: none;
}
.office-sheet-tbl {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    width: max-content;
}
.office-sheet-tbl th, .office-sheet-tbl td {
    border-right: 1px solid var(--office-sheet-grid);
    border-bottom: 1px solid var(--office-sheet-grid);
    padding: 0;
    margin: 0;
    font-weight: normal;
    overflow: hidden;
}
.office-sheet-app.office-sheet-nogrid .office-sheet-tbl th, .office-sheet-app.office-sheet-nogrid .office-sheet-tbl td { border-color: transparent; }
.office-sheet-tbl thead th {
    position: sticky;
    top: 0;
    height: 24px;
    background: var(--office-sheet-head2);
    color: var(--office-sheet-txt2);
    font-size: 11px;
    text-align: center;
    cursor: pointer;
    user-select: none;
}
.office-sheet-tbl thead th.office-sheet-on { background: var(--office-sheet-accent); color: var(--office-sheet-on); }
.office-sheet-tbl thead th.office-sheet-fzc { left: 0; }
.office-sheet-corner {
    position: sticky;
    left: 0;
    top: 0;
    width: 46px;
    background: var(--office-sheet-head2);
    cursor: pointer;
}
.office-sheet-rh {
    position: sticky;
    left: 0;
    width: 46px;
    background: var(--office-sheet-head2);
    color: var(--office-sheet-txt2);
    font-size: 11px;
    text-align: center;
    cursor: pointer;
}
.office-sheet-td {
    position: relative;
    background: var(--office-sheet-card);
    vertical-align: top;
    cursor: cell;
}
.office-sheet-cv {
    padding: 2px 4px;
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 18px;
}
.office-sheet-td.office-sheet-on { background: var(--office-sheet-selb); }
.office-sheet-td[style*="background"].office-sheet-on { box-shadow: inset 0 0 0 9999px var(--office-sheet-selb); }
.office-sheet-td.office-sheet-cur { outline: 2px solid var(--office-sheet-accent); outline-offset: -2px; }
.office-sheet-fzc { position: sticky; background: var(--office-sheet-card); }
.office-sheet-tbl thead th.office-sheet-fzc, .office-sheet-corner { background: var(--office-sheet-head2); }
.office-sheet-rsz { cursor: col-resize; }
.office-sheet-fl { font-size: 9px; margin-left: 2px; }
.office-sheet-edit {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border: 2px solid var(--office-sheet-accent);
    border-radius: 0;
    padding: 2px 4px;
    font-size: 12px;
    font-family: inherit;
    background: var(--office-sheet-inp);
    color: var(--office-sheet-txt);
    outline: none;
}
.office-sheet-fill {
    position: absolute;
    left: 0;
    top: 0;
    width: 10px;
    height: 10px;
    background: var(--office-sheet-accent);
    border: 1px solid var(--office-sheet-card);
    border-radius: 2px;
    cursor: crosshair;
}
.office-sheet-fill.office-sheet-hide { display: none; }

/* status + sheets */
.office-sheet-statusbar {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 10px;
    background: var(--office-sheet-head);
    border-top: 1px solid var(--office-sheet-line);
    font-size: 11px;
    color: var(--office-sheet-txt2);
}
.office-sheet-sheets {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 2px;
    padding: 5px 8px;
    background: var(--office-sheet-head);
    border-top: 1px solid var(--office-sheet-line);
}
.office-sheet-tab {
    padding: 5px 12px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs) var(--office-sheet-rs) 0 0;
    background: var(--office-sheet-btn);
    color: var(--office-sheet-txt);
    font-size: 12px;
    cursor: pointer;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.office-sheet-tab.office-sheet-on { background: var(--office-sheet-card); color: var(--office-sheet-accent); font-weight: 600; }
.office-sheet-tab-add {
    padding: 5px 10px;
    border: 1px dashed var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: transparent;
    color: var(--office-sheet-txt2);
    cursor: pointer;
    font-size: 13px;
}

/* chart */
.office-sheet-chartbox {
    margin: 8px;
    padding: 8px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-r);
    background: var(--office-sheet-card);
}
.office-sheet-chartbox.office-sheet-hide { display: none; }
.office-sheet-chart-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 12px; }
.office-sheet-chartbox canvas { max-width: 100%; height: auto; }

/* modal */
.office-sheet-modal {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: var(--office-sheet-mask);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}
.office-sheet-modal.office-sheet-hide { display: none; }
.office-sheet-modal-box {
    width: 100%;
    max-width: 380px;
    max-height: 90%;
    overflow: auto;
    background: var(--office-sheet-card);
    border-radius: var(--office-sheet-r);
    box-shadow: 0 6px 24px var(--office-sheet-shadow);
}
.office-sheet-modal-hd { padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--office-sheet-line); font-size: 14px; }
.office-sheet-modal-bd { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.office-sheet-modal-ft { padding: 10px 14px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--office-sheet-line); }
.office-sheet-fld { display: flex; flex-direction: column; gap: 4px; }
.office-sheet-fld-l { font-size: 11px; color: var(--office-sheet-txt2); }
.office-sheet-inp {
    padding: 5px 8px;
    border: 1px solid var(--office-sheet-line);
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-inp);
    color: var(--office-sheet-txt);
    font-size: 13px;
}
.office-sheet-fndesc { font-size: 12px; color: var(--office-sheet-txt2); padding: 6px 8px; background: var(--office-sheet-head); border-radius: var(--office-sheet-rs); }
.office-sheet-flist { max-height: 190px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.office-sheet-fitem { display: flex; align-items: center; gap: 6px; font-size: 12px; }

/* toast */
.office-sheet-toast {
    position: absolute;
    left: 50%;
    bottom: 64px;
    transform: translateX(-50%);
    padding: 7px 14px;
    border-radius: var(--office-sheet-rs);
    background: var(--office-sheet-accent);
    color: var(--office-sheet-on);
    font-size: 12px;
    box-shadow: 0 4px 12px var(--office-sheet-shadow);
}
.office-sheet-toast.office-sheet-hide { display: none; }

/* print */
.office-sheet-print { display: none; }
.office-sheet-pt { border-collapse: collapse; width: 100%; font-size: 11px; }
.office-sheet-pt th, .office-sheet-pt td { border: 1px solid var(--office-sheet-grid); padding: 2px 4px; text-align: left; }
.office-sheet-pt th { background: var(--office-sheet-head2); }

@media (max-width: 700px) {
    .office-sheet-grp { padding: 4px 6px 6px; border-right: none; border-bottom: 1px solid var(--office-sheet-line); width: 100%; }
    .office-sheet-pane.office-sheet-on { flex-direction: column; }
    .office-sheet-row-w { min-width: 0; }
    .office-sheet-sel { max-width: 120px; }
    .office-sheet-grid { max-height: 340px; }
}

@media print {
    .office-sheet-rtabs, .office-sheet-ribbon, .office-sheet-fxbar, .office-sheet-grid, .office-sheet-statusbar, .office-sheet-sheets, .office-sheet-chartbox, .office-sheet-modal, .office-sheet-toast { display: none !important; }
    .office-sheet-app { border: none; }
    .office-sheet-print { display: block !important; }
    .office-sheet-app.office-sheet-land { width: 11in; }
    @page { margin: var(--office-sheet-pmargin); }
}

/* hyperlink, comment marker, dialog textarea */
.office-sheet-lnk { color: var(--primary, #2563eb); text-decoration: underline; }
.office-sheet-note {
    position: absolute; top: 0; right: 0; width: 0; height: 0;
    border-style: solid; border-width: 0 7px 7px 0; border-color: transparent var(--danger, #dc2626) transparent transparent;
}
.office-sheet-note:hover { cursor: help; }
/* frozen cells stay sticky (sticky also creates a containing block for absolute children) */
.office-sheet-td:not(.office-sheet-fzc) { position: relative; }
.office-sheet-ta {
    width: 100%; min-height: 96px; box-sizing: border-box; resize: vertical;
    padding: 8px 10px; border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius-sm, 6px);
    background: var(--bg-input, #fff); color: var(--text, #333); font: inherit; line-height: 1.5;
}
.office-sheet-ta:focus { outline: 2px solid var(--primary, #2563eb); outline-offset: 1px; }

/* watermark */
.office-sheet-gwrap { position: relative; }
.office-sheet-wm {
    position: absolute; left: 0; top: 0; right: 0; bottom: 0;
    pointer-events: none; background-repeat: repeat; background-position: center;
}
.office-sheet-wm[hidden] { display: none !important; }
.office-sheet-print { position: relative; }
.office-sheet-pwm {
    position: absolute; left: 0; top: 0; right: 0; bottom: 0;
    pointer-events: none; background-repeat: repeat; background-position: center;
}

/* right-click context menu (rendered on document.body, must use platform-level vars) */
.office-sheet-ctx { position: absolute; min-width: 172px; max-width: 260px; padding: 4px;
    background: var(--bg-card, #ffffff); border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius-sm, 6px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .16); }
.office-sheet-ctx[hidden] { display: none; }
.office-sheet-ctxi { display: block; width: 100%; text-align: left; padding: 6px 10px;
    font-family: inherit; font-size: 13px; line-height: 1.4; color: var(--text, #333333);
    background: transparent; border: none; border-radius: var(--radius-sm, 6px); cursor: pointer; }
.office-sheet-ctxi:hover { background: var(--bg-btn-hover, #e5e7eb); }
.office-sheet-ctxsep { height: 1px; margin: 4px 6px; background: var(--border, #e5e7eb); }

/* unified ribbon control box */
.office-sheet-ribbon button { min-height: 30px; min-width: 32px; }

.office-sheet-swrow { flex-wrap: wrap; gap: 4px; }
.office-sheet-sw {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--office-sheet-line);
    border-radius: 3px;
    cursor: pointer;
    flex: 0 0 auto;
}
.office-sheet-sw:hover { outline: 2px solid var(--office-sheet-accent); }
.office-sheet-sw-none { background: var(--office-sheet-surface); position: relative; }
.office-sheet-sw-none::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 50%;
    width: 16px;
    height: 2px;
    background: var(--office-sheet-err);
    transform: rotate(-45deg);
}
