/* ==========================================================
   Spy-da Office — shared styles
   ========================================================== */
:root {
  --ink: #14161b;
  --ink-2: #1d2027;
  --ink-3: #2a2e37;
  --ink-line: #343945;
  --ink-text: #e9ebf0;
  --ink-muted: #9aa1b1;

  --paper: #ffffff;
  --canvas: #eef0f4;
  --line: #dde1e8;
  --line-2: #c9ced8;
  --text: #1b1e25;
  --muted: #646b7a;

  --brand: #e5243b;
  --docs: #2f6fed;
  --excel: #1f9d55;
  --powerpoint: #e8590c;
  --photo: #8b5cf6;
  --accent: var(--brand);

  --ok: #1f9d55;
  --warn: #c77700;
  --danger: #d6293e;

  --radius: 10px;
  --radius-s: 6px;
  --shadow-1: 0 1px 2px rgba(16, 20, 30, .06), 0 1px 3px rgba(16, 20, 30, .08);
  --shadow-2: 0 8px 28px rgba(16, 20, 30, .16), 0 2px 6px rgba(16, 20, 30, .08);
  --topbar-h: 52px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.app-docs { --accent: var(--docs); }
.app-excel { --accent: var(--excel); }
.app-powerpoint { --accent: var(--powerpoint); }
.app-photo { --accent: var(--photo); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .92em; background: #f1f3f7; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-s);
  border: 1px solid var(--line-2); background: var(--paper); color: var(--text);
  font: 500 13px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #f5f6f9; border-color: #b8beca; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.05); border-color: transparent; }

input[type=text], input[type=password], input[type=search], input[type=number], input:not([type]), select, textarea {
  font: 14px var(--font); color: var(--text);
  height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius-s);
  background: var(--paper); width: 100%;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- Auth / simple pages ---------- */
.auth-body {
  min-height: 100%; display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 40px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(229, 36, 59, .14), transparent 60%),
    var(--ink);
}
.auth-card {
  width: 100%; max-width: 440px; background: var(--paper); border-radius: 16px;
  padding: 30px 30px 34px; box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.auth-card:has(.user-table) { max-width: 640px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.auth-brand span { display: block; font-size: 12px; color: var(--muted); }
.auth-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.02em; }
.auth-card h2 { font-size: 15px; margin: 28px 0 10px; }
.form-stack { display: grid; gap: 14px; margin-top: 16px; }
.form-stack label { display: grid; gap: 6px; font-weight: 500; font-size: 13px; }
.form-stack label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form-stack .btn { justify-self: start; }
.form-stack .btn-block { justify-self: stretch; height: 40px; }
.alert { padding: 10px 12px; border-radius: var(--radius-s); margin: 14px 0; font-size: 13px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-error { background: #fdecee; color: #8e1426; border: 1px solid #f5c2c9; }
.alert-ok { background: #e7f6ee; color: #11603a; border: 1px solid #b9e3cb; }
.link-back { text-decoration: none; font-size: 13px; color: var(--muted); }
.user-table { width: 100%; border-collapse: collapse; }
.user-table td { padding: 10px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.inline-form { display: flex; gap: 6px; }
.inline-form input { height: 28px; width: 140px; font-size: 12px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #fdecee; color: var(--brand); font-weight: 600; }

/* ---------- Top bar (all apps) ---------- */
.topbar {
  height: var(--topbar-h); background: var(--ink); color: var(--ink-text);
  display: flex; align-items: center; gap: 10px; padding: 0 10px 0 8px;
  position: relative; z-index: 50; user-select: none;
  border-bottom: 2px solid var(--accent);
}
.topbar-home { display: flex; align-items: center; padding: 4px; border-radius: 8px; }
.topbar-home:hover { background: var(--ink-3); }
.topbar-home img { width: 32px; height: 32px; display: block; }
.topbar-app { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-app img { width: 26px; height: 26px; flex: none; }
.topbar-titles { display: flex; flex-direction: column; min-width: 0; }
.topbar input.topbar-name {
  background: transparent; border: 1px solid transparent; color: #fff;
  font: 600 15px var(--font); height: 24px; padding: 0 6px; margin-left: -6px; border-radius: 4px;
  width: auto; min-width: 60px; max-width: 360px;
}
.topbar input.topbar-name:hover { border-color: var(--ink-line); }
.topbar input.topbar-name:focus { background: var(--ink-2); border-color: var(--accent); box-shadow: none; }
.topbar-menus { display: flex; align-items: center; height: 20px; margin-left: -4px; }
.menu-btn {
  background: none; border: 0; color: var(--ink-muted); font: 13px var(--font);
  padding: 1px 7px; border-radius: 4px; cursor: pointer; height: 20px;
}
.menu-btn:hover, .menu-btn.open { background: var(--ink-3); color: #fff; }
.topbar-status { font-size: 12px; color: var(--ink-muted); margin-left: 6px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.topbar-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); }
.topbar-status.saved .dot { background: #3ccf7a; }
.topbar-status.saving .dot { background: #f5b83d; animation: pulse 1s infinite; }
.topbar-status.error { color: #ff8a98; }
.topbar-status.error .dot { background: #ff5a6e; }
@keyframes pulse { 50% { opacity: .35; } }
.topbar-spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar .btn { height: 32px; background: var(--ink-3); border-color: var(--ink-line); color: #fff; }
.topbar .btn:hover { background: #363b46; }
.topbar .btn-primary { background: var(--accent); border-color: var(--accent); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--ink-3); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 13px; text-transform: uppercase;
  text-decoration: none; border: 1px solid var(--ink-line);
}
.avatar:hover { border-color: var(--accent); }

/* Dropdown menus */
.dropdown {
  position: fixed; z-index: 1000; min-width: 230px; background: var(--paper); color: var(--text);
  border-radius: 8px; box-shadow: var(--shadow-2); padding: 5px; border: 1px solid var(--line);
}
.dropdown button {
  display: flex; width: 100%; align-items: center; gap: 10px; padding: 7px 10px;
  background: none; border: 0; border-radius: 5px; font: 13px var(--font); color: var(--text); cursor: pointer; text-align: left;
}
.dropdown button:hover { background: #f1f3f7; }
.dropdown button:disabled { color: #a9afbb; cursor: default; background: none; }
.dropdown .kbd { margin-left: auto; color: var(--muted); font-size: 11px; }
.dropdown hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.dropdown .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 2px; }

/* ---------- App body ---------- */
.app-body { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.app-main { flex: 1; min-height: 0; position: relative; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(12, 14, 18, .5); z-index: 2000;
  display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px;
  animation: fadein .12s ease-out;
}
.modal {
  background: var(--paper); border-radius: 14px; width: 100%; max-width: 460px;
  box-shadow: var(--shadow-2); display: flex; flex-direction: column; max-height: 80vh;
  animation: rise .16s ease-out;
}
.modal.wide { max-width: 760px; }
.modal-head { padding: 18px 20px 6px; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.modal-body { padding: 8px 20px 4px; overflow: auto; }
.modal-body p { margin: 4px 0 10px; color: var(--muted); }
.modal-foot { padding: 14px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fadein { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* File picker list inside modals */
.file-list { display: grid; gap: 2px; margin: 6px 0; }
.file-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 0; background: none; width: 100%; text-align: left; font: inherit; color: inherit;
}
.file-row:hover { background: #f1f3f7; }
.file-row img { width: 28px; height: 28px; }
.file-row .fname { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fdate { color: var(--muted); font-size: 12px; }
.empty-note { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 3000; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-2); animation: rise .15s ease-out; pointer-events: auto; max-width: 90vw;
}
.toast.error { background: #8e1426; }
.toast.ok { background: #11603a; }

/* Loading overlay */
.busy {
  position: fixed; inset: 0; z-index: 2500; background: rgba(255,255,255,.6);
  display: grid; place-items: center; font-weight: 500;
}
.busy::before {
  content: ""; width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .7s linear infinite;
  margin-bottom: 70px; grid-area: 1 / 1;
}
.busy span { grid-area: 1 / 1; margin-top: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toolbars (shared by editors) ---------- */
.toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 6px 10px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.tb-btn {
  height: 30px; min-width: 30px; padding: 0 7px; border: 1px solid transparent; border-radius: 5px;
  background: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  font: 13px var(--font); color: var(--text);
}
.tb-btn:hover { background: #f1f3f7; }
.tb-btn.active { background: color-mix(in srgb, var(--accent) 14%, white); color: var(--accent); }
.tb-btn svg { width: 17px; height: 17px; }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; }
.tb-select { height: 30px; width: auto; padding: 0 6px; font-size: 13px; }
.tb-color { position: relative; }
.tb-color input[type=color] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; padding: 0; border: 0; }
.tb-color .swatch { width: 16px; height: 4px; border-radius: 1px; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); }

/* ==========================================================
   Hub (home screen)
   ========================================================== */
.hub { min-height: 100%; }
.hub-top {
  background: var(--ink); color: var(--ink-text);
  padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 12px;
}
.hub-top .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.hub-top .brand img { width: 34px; height: 34px; }
.hub-hero {
  background:
    radial-gradient(900px 300px at 15% 0%, rgba(229, 36, 59, .22), transparent 60%),
    linear-gradient(var(--ink), var(--ink-2));
  color: #fff; padding: 26px 24px 34px;
}
.hub-wrap { max-width: 1120px; margin: 0 auto; }
.hub-hero h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.02em; }
.hub-hero p { margin: 0 0 22px; color: var(--ink-muted); }
.app-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.app-tile {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 14px;
  background: var(--ink-3); border: 1px solid var(--ink-line); color: #fff; text-decoration: none;
  transition: transform .12s, border-color .12s, background .12s;
}
.app-tile:hover { transform: translateY(-2px); border-color: var(--tile); background: #30353f; }
.app-tile img { width: 46px; height: 46px; flex: none; }
.app-tile strong { display: block; font-size: 15px; white-space: nowrap; }
.app-tile > div { min-width: 0; }
.app-tile span { display: block; font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.app-tile .plus { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.08); font-size: 18px; line-height: 1; }

.hub-files { padding: 26px 24px 60px; }
.hub-files-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.hub-files-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; margin-right: auto; }
.seg { display: inline-flex; background: #e3e6ec; border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; font: 500 12px var(--font); color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--paper); color: var(--text); box-shadow: var(--shadow-1); }
.hub-files-head input.hub-search { width: 240px; height: 32px; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.file-card {
  background: var(--paper); border-radius: 12px; border: 1px solid var(--line); overflow: hidden;
  cursor: pointer; transition: box-shadow .12s, border-color .12s; position: relative; text-decoration: none; color: inherit; display: block;
}
.file-card:hover { box-shadow: var(--shadow-2); border-color: var(--line-2); }
.file-thumb {
  height: 132px; background: #f4f5f8; display: grid; place-items: center; border-bottom: 1px solid var(--line);
  background-size: cover; background-position: center;
}
.file-thumb img.ph { width: 48px; height: 48px; opacity: .9; }
.file-thumb.contain { background-size: contain; background-repeat: no-repeat; background-color: #2a2e37; }
.file-info { padding: 10px 12px 12px; display: flex; gap: 10px; align-items: flex-start; }
.file-info img { width: 20px; height: 20px; margin-top: 1px; flex: none; }
.file-info .fname { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info .fdate { font-size: 12px; color: var(--muted); margin-top: 2px; }
.file-info > div { min-width: 0; flex: 1; }
.file-more {
  width: 26px; height: 26px; border-radius: 6px; border: 0; background: none; cursor: pointer; color: var(--muted);
  display: grid; place-items: center; flex: none; margin: -3px -4px 0 0; font-size: 18px; line-height: 1;
}
.file-more:hover { background: #f1f3f7; color: var(--text); }
.hub-empty {
  border: 2px dashed var(--line-2); border-radius: 14px; padding: 50px 20px; text-align: center; color: var(--muted);
}
.hub-empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

@media (max-width: 900px) {
  .app-tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .app-tiles { grid-template-columns: 1fr; }
  .hub-files-head input.hub-search { width: 100%; }
  .topbar { gap: 6px; }
  .topbar-titles { min-width: 0; }
  .topbar input.topbar-name { max-width: 42vw; }
  .topbar-menus { overflow-x: auto; max-width: 48vw; scrollbar-width: none; }
  .topbar-status span { display: none; }
  .topbar-right .btn { padding: 0 10px; }
}
