/* Document Editor v1.3 — styles for the added features */

/* open-document tabs */
#doctabs { display: none; align-items: stretch; gap: 2px; padding: 4px 8px 0; padding-inline-start: 32px; background: var(--adgsc-canvas); border-bottom: 1px solid var(--line); overflow-x: auto; flex-shrink: 0; }
#doctabs.has { display: flex; }
.doctab { display: flex; align-items: center; gap: 6px; max-width: 240px; min-height: 36px; padding: 0 4px 0 12px; padding-inline: 12px 4px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--hdr); color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none; }
.doctab .nm { overflow: hidden; text-overflow: ellipsis; }
.doctab.active { background: var(--panel); color: var(--text); font-weight: 600; border-top: 3px solid var(--adgsc-red); }
.doctab.dirty .nm::after { content: " ●"; color: var(--warn); }
.doctab button { min-height: 28px; min-width: 28px; padding: 0; border: 0; background: transparent; color: inherit; border-radius: 4px; }
.doctab button:hover { background: rgba(127,127,127,.2); }

/* second toolbar row + small controls */
.toolbar .grow { flex: 1; }
#xFilter { height: 44px; width: 150px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; font: inherit; background: #fff; color: #182B41; }
.toolbar select { max-width: 170px; }

/* grid extras */
#gridwrap { position: relative; }
#fillHandle { position: absolute; width: 9px; height: 9px; background: var(--sel); border: 1px solid #fff; cursor: crosshair; z-index: 1; display: none; }
.grid td.fillprev { box-shadow: inset 0 0 0 9999px rgba(31,95,191,.18); }
.grid tr.filtered-out { display: none; }
.grid thead th.resizing, .grid thead th.can-resize { cursor: col-resize; }
.grid td.found { outline: 2px solid var(--adgsc-red); outline-offset: -2px; }

/* find bar */
#findbar { position: absolute; top: 8px; inset-inline-end: 24px; z-index: 30; display: none; gap: 6px; align-items: center; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: 0 4px 14px rgba(14,27,44,.2); max-width: calc(100% - 48px); }
#findbar.open { display: flex; }
#findbar input { height: 44px; width: 170px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; font: inherit; unicode-bidi: plaintext; background: #fff; color: #182B41; }
#work { position: relative; }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(14,27,44,.55); display: none; align-items: center; justify-content: center; z-index: 88; padding: 16px; }
#modal.open { display: flex; }
#modal .card { background: var(--panel); color: var(--text); border-radius: 10px; max-width: 760px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
#modal .hd { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#modal .hd b { flex: 1; font-size: 16px; color: var(--adgsc-navy); }
body.dark #modal .hd b { color: var(--text); }
#modal .bd { padding: 16px; overflow: auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding: 10px; min-height: 96px; text-align: center; }
.tile .big { font-size: 28px; }
.mini { border-collapse: collapse; width: 100%; font-size: 10px; pointer-events: none; }
.mini td { height: 14px; border: 1px solid transparent; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list button { text-align: start; display: flex; gap: 8px; align-items: center; }
.list small { color: var(--muted); margin-inline-start: auto; }
#recentBox { text-align: start; }
#recentBox h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
#chartCanvas { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; }

/* Word extras */
#page .pagebreak { border-top: 2px dashed #9aa7b5; margin: 16px 0; height: 0; position: relative; user-select: none; }
#page .pagebreak::after { content: "⤓"; position: absolute; top: -12px; inset-inline-start: 50%; background: #fff; color: #9aa7b5; padding: 0 6px; font-size: 12px; }
#hfNote { display: none; padding: 4px 12px; font-size: 12px; color: var(--muted); background: #F7F9FB; border-bottom: 1px solid var(--line); }
#hfNote.show { display: block; }
@media print { #printArea .pagebreak { break-after: page; border: 0; } #printArea .pagebreak::after { content: none; } }

/* header / footer previews around the Word page */
.hfprev { width: 816px; max-width: calc(100% - 32px); margin: 0 auto; padding: 8px 80px; background: #fff; color: #444; font-size: 10pt; white-space: pre-wrap; unicode-bidi: plaintext; cursor: pointer; border-bottom: 1px dashed #cfd8e2; min-height: 36px; }
#hfBottom { border-bottom: 0; border-top: 1px dashed #cfd8e2; margin-bottom: 24px; }
#hfTop { margin-top: 0; }
.hfprev.empty { color: #9aa7b5; font-style: italic; }
.hfprev:hover { background: #f7f9fb; }
#pagewrap > #page { margin-top: 0; margin-bottom: 0; }

/* pictures in the sheet */
.ximg { outline: 1px solid transparent; user-select: none; }
.ximg.sel { outline: 2px solid var(--sel); }

/* ============ ribbon (v1.4) ============ */
.ribbon { background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; position: relative; }
.rtabs { display: flex; align-items: flex-end; gap: 2px; padding: 4px 8px 0; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.rtab { min-height: 40px; padding: 6px 16px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; background: transparent; color: var(--text); white-space: nowrap; margin-bottom: -1px; }
.rtab:hover { background: var(--hdr); }
.rtab.active { background: var(--panel); border-color: var(--line); color: var(--adgsc-navy); font-weight: 600; box-shadow: inset 0 3px 0 var(--adgsc-red); }
body.dark .rtab.active { color: #fff; }
.rtab.rfile { background: var(--adgsc-navy); color: #fff; font-weight: 600; border-radius: 6px 6px 0 0; margin-inline-end: 6px; }
.rtab.rfile:hover, .rtab.rfile.open { background: var(--adgsc-navy-dark); }
.rcollapse { margin-inline-start: auto; min-height: 36px; min-width: 44px; border: 0; background: transparent; color: var(--muted); font-size: 16px; }
.rpanels { overflow-x: auto; }
.rpanel { display: flex; align-items: stretch; padding: 6px 4px 0; min-height: 92px; }
.rpanel[hidden] { display: none; }
.rgroup { display: flex; flex-direction: column; padding: 0 8px; border-inline-end: 1px solid var(--line); flex: 0 1 auto; min-width: 0; }
.rgroup:last-child { border-inline-end: 0; }
.rbody { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; align-content: flex-start; flex: 1; max-width: 420px; }
.rgroup.g-small .rbody { max-width: 250px; }
.rcap { font-size: 11px; color: var(--muted); text-align: center; padding: 3px 0 4px; white-space: nowrap; }
.rbody button { padding: 4px 10px; min-width: 44px; min-height: 44px; }
.rbody select { max-width: 160px; }
.rcolor { display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: 12px; color: var(--muted); cursor: pointer; }
.rcolor input[type=color] { border: 0; width: 32px; height: 32px; padding: 0; background: transparent; }
.ribbon #xFilter { width: 160px; }
.ribbon.collapsed .rpanels { display: none; }
.ribbon.collapsed.peek .rpanels { display: block; position: absolute; inset-inline: 0; top: 100%; z-index: 40; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 6px 14px rgba(14,27,44,.18); }

/* File menu */
#fileMenu { position: fixed; z-index: 95; min-width: 260px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(14,27,44,.25); padding: 6px; display: flex; flex-direction: column; }
#fileMenu[hidden] { display: none; }
#fileMenu button { display: flex; align-items: center; gap: 10px; min-height: 44px; border: 0; background: transparent; text-align: start; padding: 6px 12px; border-radius: 6px; color: var(--text); }
#fileMenu button:hover:not(:disabled), #fileMenu button:focus-visible { background: var(--hdr); }
#fileMenu .ico { width: 22px; text-align: center; }
#fileMenu .txt { flex: 1; }
#fileMenu kbd { font: 11px "Segoe UI", sans-serif; color: var(--muted); direction: ltr; }
#fileMenu .fmsep { height: 1px; background: var(--line); margin: 4px 6px; }

@media (max-width: 640px) {
  #btnLang { display: none; }   /* still in View ▸ Language and in the side menu */
  #header { overflow: hidden; }
  .rpanel { min-height: 0; }
  .rbody { flex-wrap: nowrap; max-width: none !important; }
  .rgroup { flex-shrink: 0; }
  .rbody button { white-space: nowrap; }
  .rtab { padding: 6px 10px; }
}

/* AI quick actions */
#aiQuick { display: flex; gap: 6px; flex-wrap: wrap; }
#aiQuick button { min-height: 36px; padding: 2px 10px; font-size: 13px; }

/* dark mode: canvas, panels and toolbars go dark; the header and footer stay light so the
   original red logo keeps its approved light background; the sheet and the page stay white. */
body.dark { --adgsc-canvas: #0F1722; --adgsc-panel: #17212F; --adgsc-line: #2A3A4E; --adgsc-text: #E6EDF5; --adgsc-muted: #9FB2C8; --hdr: #1C2838; color-scheme: dark;
  --bg: #0F1722; --panel: #17212F; --line: #2A3A4E; --text: #E6EDF5; --muted: #9FB2C8; background: #0F1722; color: #E6EDF5; }
body.dark button { background: #1C2838; color: #E6EDF5; }
body.dark button:hover { background: #243449; }
body.dark button.on { background: #2B4468; border-color: #7FA6DB; }
body.dark button.primary { background: var(--adgsc-red); color: #fff; }
body.dark select, body.dark #cellname, body.dark #formula, body.dark #ask, body.dark #keybox input { background: #1C2838; color: #E6EDF5; border-color: #2A3A4E; }
body.dark #header, body.dark #footer { --adgsc-panel: #FFFFFF; --adgsc-text: #182B41; --adgsc-muted: #67798D; --adgsc-line: #D7E0E8; --panel: #FFFFFF; --text: #182B41; --muted: #67798D; --line: #D7E0E8; color: #182B41; color-scheme: light; }
body.dark #header button:not(.primary) { background: #fff; color: #182B41; }
body.dark #header .ident b { color: #14263E; }
body.dark #welcome h1 { color: var(--adgsc-text); }
body.dark #welcome .drop, body.dark #hfNote { background: #1C2838; }
body.dark .tab { color: #9FB2C8; }
body.dark .tab.active { background: #17212F; color: #fff; border-bottom-color: var(--adgsc-red); }
body.dark #pagewrap { background: #0B111A; }
body.dark .msg.user { background: #22395A; } body.dark .msg.bot { background: #1C2838; } body.dark .msg.err { background: #4A1F24; color: #FFD7DB; }
body.dark .grid th { color: #C5D2E0; }
body.dark #gridnote { background: #2B2A1A; }

/* ---------- voice typing (voice.js) ---------- */
.micwrap { display: inline-flex; gap: 2px; align-items: center; }
.micwrap .micbtn.on { background: #FDE8EA; border-color: var(--adgsc-red); color: var(--adgsc-red); }
.micwrap .miclang { min-width: 44px; padding: 4px 8px; font-weight: 600; }
#askrow .micwrap.ai .micbtn { white-space: nowrap; }
#micInterim { position: fixed; bottom: 56px; inset-inline-start: 50%; transform: translateX(50%); max-width: 70vw; padding: 8px 14px; border-radius: 8px; background: var(--adgsc-navy); color: #fff; font-size: 15px; z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
html[dir=ltr] #micInterim { transform: translateX(-50%); }
body.dark .micwrap .micbtn.on { background: #4A1B20; }
