/* Copyediting Enterprise — design system (single source of UI truth).
 * Loaded by every page shell. Tokens first, then base, layout, components. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #1b1f24;
  --muted: #5b6571;
  --accent: #3b5bdb;
  --accent-ink: #2742a8;
  --accent-soft: #e8edfb;
  --green: #1f9d57; --green-soft: #e4f6ec;
  --red: #d23f57; --red-soft: #fce8ec;
  --amber: #b7791f; --amber-soft: #fdf2dc;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 8px 30px rgba(16,24,40,.16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; font-weight: 650; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }

/* ---- App shell / header ---- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); }
.app-header .brand .logo {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #6f86e8);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .85rem;
}
.app-nav { display: flex; gap: .25rem; }
.app-nav a {
  padding: .35rem .7rem; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: .92rem;
}
.app-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.app-nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.app-user { display: flex; align-items: center; gap: .6rem; font-size: .88rem; color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}
.container { max-width: 1040px; margin: 1.5rem auto; padding: 0 1.25rem; }
.page-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.card + .card { margin-top: 1rem; }
.card-title { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-title h2, .card-title h3 { margin: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s, transform .02s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--red); border-color: #f1c9d1; background: var(--red-soft); }
.btn.danger:hover { background: #f8d7de; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { padding: .3rem .6rem; font-size: .84rem; }
.btn-group { display: inline-flex; gap: .4rem; flex-wrap: wrap; }

/* ---- Forms ---- */
label.field { display: block; margin-bottom: .7rem; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .65rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
/* Keyboard focus ring for interactive elements (a11y, EXEC-150). */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}
/* Skip-to-content link: off-screen until focused. */
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  background: var(--accent); color: #fff; padding: .5rem .8rem; border-radius: 6px;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; outline: 2px solid #fff; }

/* Contextual help tooltips (EXEC-180). */
.help-tip {
  position: absolute; z-index: 90; max-width: 280px;
  background: #1b1f24; color: #fff; padding: .5rem .65rem; border-radius: 8px;
  font-size: .8rem; line-height: 1.35; box-shadow: var(--shadow-lg); pointer-events: none;
}
.help-tip-title { display: block; margin-bottom: .15rem; }
.help-tip-body { opacity: .92; }
.has-help { cursor: help; }
input.has-help, select.has-help, textarea.has-help, button.has-help { cursor: auto; }

/* Guided tour coachmarks (EXEC-182). */
.tour-overlay { position: fixed; inset: 0; z-index: 200; background: transparent; }
.tour-highlight {
  position: fixed; z-index: 201; border-radius: 8px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(15, 19, 26, .55); transition: all .2s ease;
}
.tour-bubble {
  position: fixed; z-index: 202; width: 300px; max-width: 92vw; box-shadow: var(--shadow-lg);
}
.tour-bubble h3 { margin: 0 0 .3rem; }

textarea { min-height: 11rem; resize: vertical; }
textarea.manuscript { font-family: var(--serif); font-size: 1.02rem; line-height: 1.7; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .12rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 650;
  background: var(--surface-2); color: var(--muted);
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--accent-soft); color: var(--accent-ink); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tab {
  padding: .55rem .85rem; border: none; background: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.data tr:hover td { background: var(--surface-2); }

/* ---- Task list ---- */
.task-card {
  display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.task-card:hover { border-color: #c7d0dd; box-shadow: var(--shadow); }
.task-card .title { font-weight: 600; }
.task-card .meta { color: var(--muted); font-size: .85rem; }

/* ---- Empty / loading states ---- */
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty .big { font-size: 2rem; margin-bottom: .3rem; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Progress ---- */
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.stage-list { list-style: none; padding: 0; margin: .6rem 0 0; }
.stage-list li { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; font-size: .88rem; color: var(--muted); }
.stage-list li .badge { font-size: .7rem; }

/* ---- Correction groups ---- */
.group { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: .6rem; overflow: hidden; }
.group > .ghead { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; background: var(--surface-2); cursor: pointer; }
.group > .ghead .title { font-weight: 600; }
.group > .gbody { padding: .5rem .8rem; display: none; }
.group.open > .gbody { display: block; }
.group.rejected { opacity: .6; }
.suggestion { padding: .4rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.suggestion:last-child { border-bottom: none; }
.suggestion del { color: var(--red); background: var(--red-soft); text-decoration: line-through; padding: 0 2px; border-radius: 3px; }
.suggestion ins { color: var(--green); background: var(--green-soft); text-decoration: none; padding: 0 2px; border-radius: 3px; }

/* ---- Redline ---- */
.redline { font-family: var(--serif); font-size: 1.05rem; line-height: 1.9; white-space: pre-wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.redline ins { color: var(--green); background: var(--green-soft); text-decoration: none; border-radius: 3px; padding: 0 1px; }
.redline del { color: var(--red); background: var(--red-soft); text-decoration: line-through; border-radius: 3px; padding: 0 1px; }

/* ---- References ---- */
.ref { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .8rem; margin-bottom: .5rem; }
.ref .raw { font-size: .9rem; }
.ref .refmeta { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .35rem; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.statcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.statcard .n { font-size: 1.6rem; font-weight: 700; }
.statcard .l { color: var(--muted); font-size: .82rem; }

/* ---- Toasts ---- */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--text); color: #fff; padding: .6rem .9rem; border-radius: 8px;
  box-shadow: var(--shadow-lg); font-size: .9rem; max-width: 340px; animation: slidein .2s ease;
}
.toast.success { background: var(--green); } .toast.error { background: var(--red); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

/* ---- Drawer (assistant) ---- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 380px; max-width: 90vw; z-index: 50;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform .2s;
}
.drawer.open { transform: translateX(0); }
.drawer .dhead { display: flex; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.drawer .dbody { padding: 1rem; overflow-y: auto; flex: 1; }
.action-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .7rem; margin-bottom: .5rem; font-size: .88rem; }

/* ---- Auth ---- */
.auth-wrap { max-width: 420px; margin: 4rem auto; }
.auth-wrap .logo-lg { width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--accent), #6f86e8); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.3rem; }

/* --- Responsive / mobile (EXEC-151) --------------------------------------- */
@media (max-width: 760px) {
  /* Header wraps instead of overflowing; nav stays usable. */
  .app-header { flex-wrap: wrap; gap: .5rem .75rem; padding: .55rem .9rem; }
  .app-header .spacer { display: none; }
  .app-nav { gap: .15rem; flex-wrap: wrap; }
  .app-user { font-size: .82rem; gap: .4rem; flex-wrap: wrap; }
  .app-user > span { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .container { margin: 1rem auto; padding: 0 .8rem; }

  /* Toolbars with many filters wrap to new lines rather than clip. */
  .card-title { flex-wrap: wrap; row-gap: .4rem; }
  .card-title input[type="search"], .card-title select { flex: 1 1 8rem; min-width: 0; }

  /* Cards and inputs go full width; reduce padding. */
  .card { padding: .9rem; }
  .row.wrap { row-gap: .4rem; }

  /* Modal becomes near-full-width and starts higher. */
  .card[role="dialog"] { top: 6% !important; width: 94vw !important; }

  /* Board columns shrink a touch and keep horizontal scroll. */
  .board-col { flex-basis: 200px; min-width: 200px; }
}

@media (max-width: 420px) {
  .app-user > span { display: none; }   /* drop the email text on very small screens */
  .btn { padding: .4rem .6rem; }
}
