/* ============================================================
   OfficeSuite Pro — Microsoft Office-style ribbon UI
   ============================================================ */
:root {
  --brand: #185abd;
  --brand-2: #2b7cde;
  --accent: #f3c623;
  --title-h: 40px;
  --ribbon-h: 34px;
  --tabs-h: 42px;
  --status-h: 26px;
  --radius: 6px;

  /* Light theme */
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e2e6ea;
  --text: #1f2430;
  --muted: #5b6472;   /* AA: muted text on white ~5.5:1 */
  --hover: rgba(24, 90, 189, 0.10);
  --active: rgba(24, 90, 189, 0.18);
  --shadow: 0 2px 10px rgba(20, 30, 60, 0.08);
  --shadow-lg: 0 8px 30px rgba(20, 30, 60, 0.16);
  --scroll: #cbd5e1;
  --ok: #15803d;      /* AA: green text on white ~4.6:1 */
  --danger: #b91c1c;  /* AA: red text on white ~6.0:1 */
  --warn: #b45309;    /* AA: amber text on white ~4.6:1 */
}
[data-theme="dark"] {
  --bg: #1b1e26;
  --panel: #242834;
  --panel-2: #2a2f3d;
  --line: #363c4c;
  --text: #e7e9ee;
  --muted: #9aa2b1;
  --hover: rgba(90, 180, 255, 0.12);
  --active: rgba(90, 180, 255, 0.22);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --scroll: #4a5266;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

/* Accessibility: visible focus, skip link, reduced motion, contrast */
:focus-visible {
  outline: 3px solid var(--brand-2);
  outline-offset: 2px;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 5000;
  background: var(--brand); color: #fff; padding: 10px 16px;
  border-radius: 0 0 6px 0; font-size: 14px; font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { left: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
::selection { background: var(--active); }
body.menu-open, body.modal-open { overflow: hidden; }
body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: background .2s, color .2s;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: var(--text); }
svg { display: block; }
.icon { width: 16px; height: 16px; flex: none; }
.hidden { display: none !important; }

/* ---------------- Title bar ---------------- */
.titlebar {
  height: var(--title-h);
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  flex: none;
  user-select: none;
}
.titlebar .logo {
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px;
  white-space: nowrap;
}
.titlebar .logo svg { width: 22px; height: 22px; }
.titlebar .docname { flex: 1; min-width: 0; }
.titlebar .docname input {
  width: 100%; max-width: 360px; border: none; background: transparent;
  color: #fff; font-size: 14px; font-weight: 500; padding: 4px 8px; border-radius: 4px;
}
.titlebar .docname input:focus { background: rgba(255,255,255,.18); outline: none; }
.titlebar .status { font-size: 11px; opacity: .85; white-space: nowrap; }
.titlebar .tb-actions { display: flex; align-items: center; gap: 4px; }
.titlebar button {
  background: transparent; border: none; color: #fff; border-radius: 4px;
  width: 30px; height: 30px; display: grid; place-items: center; transition: background .15s;
}
.titlebar button:hover { background: rgba(255,255,255,.2); }
.titlebar button:active { background: rgba(255,255,255,.3); }

/* ---------------- Ribbon ---------------- */
.ribbon { background: var(--panel); border-bottom: 1px solid var(--line); flex: none; box-shadow: var(--shadow); }
.tabstrip { display: flex; gap: 2px; padding: 0 6px; height: var(--tabs-h); align-items: stretch; }
.tabstrip .tab {
  border: none; background: transparent; color: var(--muted);
  font-size: 13px; padding: 0 14px; border-radius: 5px 5px 0 0; font-weight: 500;
  border-bottom: 2px solid transparent; display: flex; align-items: center; gap: 6px;
  transition: color .15s, background .15s;
}
.tabstrip .tab:hover { background: var(--hover); color: var(--text); }
.tabstrip .tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabstrip .tab svg { width: 15px; height: 15px; }

.tabpanel { display: none; padding: 6px 8px; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
.tabpanel.active { display: flex; gap: 6px; align-items: stretch; }
.group {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px 10px; border-right: 1px solid var(--line); gap: 4px; flex: none;
  min-width: 64px;
}
.group:last-child { border-right: none; }
.group .g-label { font-size: 10px; color: var(--muted); letter-spacing: .3px; margin-top: 2px; white-space: nowrap; }
.group .g-row { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; }
.ribbon button {
  background: transparent; border: 1px solid transparent; color: var(--text);
  border-radius: 5px; height: 30px; min-width: 30px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 12.5px; white-space: nowrap; transition: background .12s;
}
.ribbon button:hover:not(:disabled) { background: var(--hover); border-color: var(--line); }
.ribbon button:active:not(:disabled) { background: var(--active); }
.ribbon button:disabled { opacity: .38; cursor: default; }
.ribbon button.toggle.on { background: var(--active); border-color: var(--brand); color: var(--brand); }
.ribbon button svg { width: 15px; height: 15px; }
.ribbon button.span { flex: 1; justify-content: center; }
.ribbon select, .ribbon input[type=color] {
  height: 30px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 5px; padding: 0 6px; font-size: 12.5px;
}
.ribbon input[type=color] { width: 34px; padding: 2px; cursor: pointer; }
.ribbon .fontsize { width: 52px; }
.ribbon .fontname { width: 130px; }

/* ---------------- Toolbars / editor chrome ---------------- */
.toolbar {
  background: var(--panel); border-bottom: 1px solid var(--line); padding: 6px 10px;
  display: flex; gap: 6px; align-items: center; flex: none; flex-wrap: wrap;
}
.toolbar button { height: 28px; min-width: 28px; }
.fxbar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; flex: none; }
.fxbar .namebox { width: 64px; text-align: center; font-weight: 600; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 4px 2px; }
.fxbar .fxbox { flex: 1; display: flex; align-items: center; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.fxbar .fxbox .fx { padding: 4px 8px; font-size: 12px; color: var(--muted); background: transparent; }
.fxbar .fxbox input { flex: 1; border: none; background: transparent; padding: 4px 8px; font-size: 13px; outline: none; }

/* ---------------- Main content ---------------- */
main { flex: 1; overflow: hidden; position: relative; display: flex; flex-direction: column; }

/* Dashboard */
#dashboard { flex: 1; overflow-y: auto; }
.home-top { background: linear-gradient(135deg, #144a9e, #2b7cde); color: #fff; padding: 26px 28px; }
.home-top h1 { margin: 0 0 4px; font-size: 22px; }
.home-top p { margin: 0 0 16px; opacity: .9; }
.tpl-row { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 4px; }
.tpl {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 14px; width: 132px; flex: none; text-align: center;
  cursor: pointer; transition: transform .15s, background .15s;
}
.tpl:hover { transform: translateY(-2px); background: rgba(255,255,255,.22); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tpl-grid .tpl { width: auto; text-align: left; padding: 0; }
.tpl-preview { width: 100%; height: 76px; }
.tpl .tpl-icon { width: 48px; height: 48px; margin: 0 auto 8px; border-radius: 10px; display: grid; place-items: center; }
.tpl .tpl-icon svg { width: 26px; height: 26px; }
.tpl .tpl-name { font-size: 12.5px; font-weight: 500; }
.tpl .tpl-desc { font-size: 10.5px; opacity: .8; margin-top: 2px; }

.home-body { padding: 22px 28px; }
.home-body h2 { font-size: 16px; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
.section-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.grid-docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.doc-card {
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  cursor: pointer; overflow: hidden; transition: transform .15s, box-shadow .15s; position: relative;
}
.doc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.doc-card .thumb { height: 96px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.doc-card .meta { padding: 8px 10px; }
.doc-card .meta .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-card .meta .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.doc-card .card-menu { position: absolute; top: 6px; right: 6px; opacity: 0; transition: opacity .15s;
  background: rgba(0,0,0,.45); color: #fff; border: none; border-radius: 4px; width: 24px; height: 24px; }
.doc-card:hover .card-menu { opacity: 1; }

/* Word canvas */
.editor-scroll { flex: 1; overflow: auto; padding: 28px; background:
  repeating-conic-gradient(var(--bg) 0% 25%, transparent 0% 50%) 50% / 22px 22px; }
.paper { max-width: 794px; margin: 0 auto; background: var(--panel); color: var(--text);
  box-shadow: var(--shadow-lg); min-height: 1000px; padding: 64px 64px; border-radius: 2px; }
#word-canvas { outline: none; min-height: 100%; font-size: 12pt; line-height: 1.6; }
#word-canvas h1 { font-size: 24pt; } #word-canvas h2 { font-size: 19pt; }
#word-canvas h3 { font-size: 15pt; }
#word-canvas table { border-collapse: collapse; width: 100%; margin: 8px 0; }
#word-canvas table td, #word-canvas table th { border: 1px solid var(--muted); padding: 4px 8px; }
#word-canvas img { max-width: 100%; }

/* Excel grid */
.grid-scroll { flex: 1; overflow: auto; position: relative; background: var(--panel); }
.grid-table { border-collapse: collapse; }
.grid-table td, .grid-table th {
  width: 96px; min-width: 96px; height: 24px; border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); padding: 0 5px; font-size: 12px; position: relative;
  overflow: hidden; white-space: nowrap; cursor: cell; user-select: none;
}
.grid-table td.editing { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid-table td.sel { background: rgba(24,90,189,.12); }
.grid-table th.colhead {
  position: sticky; top: 0; z-index: 2; background: var(--panel-2); text-align: center;
  font-size: 11px; color: var(--muted); cursor: pointer; font-weight: 500;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.grid-table th.rowhead { position: sticky; left: 0; z-index: 2; background: var(--panel-2);
  text-align: center; font-size: 11px; color: var(--muted); min-width: 40px; width: 40px; font-weight: 500; }
.grid-table th.corner { position: sticky; top: 0; left: 0; z-index: 3; background: var(--line); }

/* PPT */
.ppt-stage { flex: 1; display: flex; flex-direction: column; }
.ppt-split { flex: 1; display: flex; overflow: hidden; }
.ppt-thumbs { width: 150px; background: var(--panel-2); border-right: 1px solid var(--line); overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 10px; }
.ppt-thumb { aspect-ratio: 4/3; background: var(--panel); border: 2px solid transparent; border-radius: 4px; box-shadow: var(--shadow); cursor: pointer; padding: 6px; font-size: 7px; position: relative; }
.ppt-thumb.active { border-color: var(--brand); }
.ppt-thumb .num { position: absolute; top: 2px; right: 4px; font-size: 9px; color: var(--muted); }
.ppt-canvas-wrap { flex: 1; display: grid; place-items: center; background: var(--bg); overflow: auto; padding: 20px; }
.ppt-canvas { width: 780px; height: 585px; background: var(--panel); box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden; border-radius: 2px; }
.ppt-shape { position: absolute; cursor: move; user-select: none; }
.ppt-shape.selected { outline: 2px solid var(--brand); }
.ppt-shape textarea { width: 100%; height: 100%; border: none; background: transparent; resize: none;
  outline: none; font-family: inherit; overflow: hidden; }
.ppt-shape .resize { position: absolute; width: 10px; height: 10px; background: var(--brand); border: 1px solid #fff; }

/* PDF */
.pdf-view { flex: 1; display: flex; flex-direction: column; }
.pdf-embed { flex: 1; border: none; background: #525659; width: 100%; }

/* Notes */
.notes-wrap { flex: 1; overflow: auto; padding: 20px; }
.notes-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.note-card { background: #fef9c3; color: #3b3a1f; padding: 14px; border-radius: 8px; min-height: 120px;
  box-shadow: var(--shadow); cursor: pointer; position: relative; }
[data-theme="dark"] .note-card { background: #3a3520; color: #efe8c8; }
.note-card .note-title { font-weight: 700; margin-bottom: 6px; }
.note-card .note-body { font-size: 12.5px; white-space: pre-wrap; overflow: hidden; }
.note-card .note-del { position: absolute; top: 6px; right: 6px; background: none; border: none;
  color: inherit; opacity: .5; }
.note-card .note-del:hover { opacity: 1; }
.note-edit { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.note-edit input[type=text] { font-size: 20px; font-weight: 700; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); }
.note-edit textarea { min-height: 60vh; padding: 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); line-height: 1.6; resize: none; outline: none; }
.note-edit textarea:focus { border-color: var(--brand); }

/* Code editor syntax highlight overlay */
.code-wrap .code-hl {
  position: absolute; inset: 0; margin: 0; overflow: auto; pointer-events: none;
  font-family: Consolas, Menlo, monospace; font-size: 13px; line-height: 1.5;
  padding: 10px; color: var(--text); white-space: pre; background: var(--panel);
}
.code-wrap textarea { color: transparent; background: transparent !important; }
.code-wrap textarea::selection { background: var(--active); color: transparent; }
.code-wrap .code-hint {
  position: absolute; display: none; z-index: 5; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow-lg);
  padding: 4px 8px; font-family: Consolas, Menlo, monospace; font-size: 12px;
  color: var(--brand); pointer-events: none; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Context menu */
.ctx-menu { position: fixed; z-index: 999; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow-lg); padding: 4px; min-width: 180px; display: none; }
.ctx-menu .mi { padding: 7px 12px; font-size: 13px; border-radius: 5px; display: flex; gap: 8px; align-items: center; }
.ctx-menu .mi:hover { background: var(--hover); }
.ctx-menu .sep { border-top: 1px solid var(--line); margin: 4px 6px; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,15,30,.5); display: grid;
  place-items: center; z-index: 1000; backdrop-filter: blur(2px); }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(440px, 92vw); }
.modal .m-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal .m-head h3 { margin: 0; font-size: 16px; }
.modal .m-body { padding: 8px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.modal input, .modal select, .modal textarea { border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.modal textarea { min-height: 90px; resize: vertical; }
.modal .m-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 6px;
  padding: 8px 14px; font-size: 13px; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Toast */
.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-lg); display: flex; gap: 8px; align-items: center; animation: slideUp .25s; max-width: 90vw; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Status bar */
.statusbar { height: var(--status-h); background: var(--panel); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 18px; padding: 0 12px; font-size: 11.5px; color: var(--muted); flex: none; }
.statusbar .spacer { flex: 1; }
.statusbar .pill { display: flex; align-items: center; gap: 4px; }

/* Offline banner */
.offline-banner { background: #d97706; color: #fff; font-size: 12px; text-align: center; padding: 3px 10px; flex: none; }

/* Responsive */
@media (max-width: 820px) {
  .titlebar .docname { display: none; }
  .tabstrip .tab span { display: none; }
  .tabstrip .tab { padding: 0 10px; }
  .home-top, .home-body { padding: 16px; }
  .paper { padding: 28px 20px; }
  .ppt-split { flex-direction: column; }
  .ppt-thumbs { width: 100%; height: 96px; flex-direction: row; border-right: none; border-bottom: 1px solid var(--line); }
  .ppt-thumb { width: 70px; aspect-ratio: 4/3; flex: none; }
  .ppt-canvas { width: 100%; }
}
@media (max-width: 520px) {
  .titlebar .logo span { display: none; }
  .group { min-width: 0; }
  .ribbon .fontname { width: 90px; }
  .grid-docs { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
