:root {
  --ink: #18212f;
  --muted: #5d6879;
  --line: #dfe4ea;
  --bg: #f3f5f8;
  --card: #ffffff;
  --brand: #1f3a5f;
  --brand-2: #2e6da4;
  --focus: #2e6da4;
  --green: #1e7d45;   --green-bg: #e3f4ea;
  --red: #b42318;     --red-bg: #fde8e7;
  --yellow: #8a5a00;  --yellow-bg: #fff3cd;
  --blue: #1f5fa8;    --blue-bg: #e3eefa;
  --orange: #a84b00;  --orange-bg: #fde9d9;
  --grey: #535c69;    --grey-bg: #eceff3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Rubik", "Heebo", Arial, sans-serif;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2 { margin: 0 0 .6rem; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); margin: .2rem 0 1rem; }
.hint { color: var(--muted); font-size: .88rem; margin: .4rem 0; }
a { color: var(--brand-2); }

/* --- top bar ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .6rem 1.25rem; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.brand-mark {
  background: #fff; color: var(--brand); border-radius: 8px; padding: .1rem .5rem;
  font-weight: 800; letter-spacing: .04em; direction: ltr;
}
.brand-mark.big { font-size: 1.35rem; padding: .2rem .7rem; background: var(--brand); color: #fff; }
.brand-text { font-size: 1.05rem; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs a {
  color: #d7e3f1; text-decoration: none; padding: .45rem .8rem; border-radius: 8px; font-weight: 600;
}
.tabs a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.tabs a.active { background: #fff; color: var(--brand); }
.usermenu { margin-inline-start: auto; display: flex; align-items: center; gap: .75rem; font-size: .92rem; }
.whoami { opacity: .9; }
.linkbtn { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

main { max-width: 1040px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* --- buttons / forms ---------------------------------------------------------- */
.btn {
  font: inherit; font-weight: 700; border-radius: 10px; border: 1px solid transparent;
  padding: .65rem 1.2rem; cursor: pointer; min-height: 44px;
}
.btn.primary { background: var(--brand-2); color: #fff; }
.btn.primary:hover { background: #255a88; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.small { padding: .3rem .65rem; min-height: 32px; font-size: .85rem; font-weight: 600; }
.btn.danger { background: #fff; border-color: #f1b5b0; color: var(--red); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.wide { width: 100%; }
input, select {
  font: inherit; color: inherit; width: 100%; padding: .6rem .75rem; min-height: 44px;
  border: 1px solid #c7ced8; border-radius: 10px; background: #fff;
}
input:focus, select:focus, .btn:focus-visible, .tabs a:focus-visible {
  outline: 3px solid rgba(46, 109, 164, .35); outline-offset: 1px; border-color: var(--focus);
}
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .8rem; }
label > input, label > select { margin-top: .3rem; font-weight: 400; }
.form-error {
  background: var(--red-bg); color: var(--red); border-radius: 8px; padding: .55rem .8rem; margin: .5rem 0;
  font-weight: 600;
}
.row-actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }

/* --- auth --------------------------------------------------------------------- */
.auth-view { display: grid; place-items: center; min-height: 80vh; }
.auth-card {
  width: min(420px, 100%); background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}
.auth-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.2rem; }
.auth-brand h1 { margin: 0; }

/* --- panels ------------------------------------------------------------------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.notice { background: var(--blue-bg); border-radius: 10px; padding: .8rem 1rem; margin-top: .75rem; }
.notice code, .pw {
  direction: ltr; unicode-bidi: embed; font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem;
  background: #fff; padding: .1rem .45rem; border-radius: 6px; border: 1px solid var(--line);
}

/* --- search ------------------------------------------------------------------- */
.searchbar { display: flex; gap: .6rem; margin-bottom: 1.1rem; }
.searchbar input { font-size: 1.1rem; min-height: 52px; }
.searchbar .btn { min-width: 110px; }
.result-head { color: var(--muted); margin: 0 0 .75rem; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 1rem; overflow: hidden; border-top: 5px solid var(--grey);
}
.card.tone-green { border-top-color: var(--green); }
.card.tone-red { border-top-color: var(--red); }
.card.tone-yellow { border-top-color: #e0a800; }
.card.tone-blue { border-top-color: var(--blue); }
.card.tone-orange { border-top-color: var(--orange); }
.card-label { background: #f7f9fb; border-bottom: 1px solid var(--line); padding: .45rem 1.1rem; font-weight: 700; font-size: .92rem; color: var(--muted); }
.card-body { padding: 1.1rem; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; }
.status-big { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .35rem; }
.pill {
  display: inline-block; border-radius: 999px; padding: .15rem .7rem; font-weight: 700; font-size: .9rem;
  background: var(--grey-bg); color: var(--grey); white-space: nowrap;
}
.pill.big { font-size: 1.6rem; padding: .25rem 1.1rem; }
.tone-green .pill.big, .pill.tone-green { background: var(--green-bg); color: var(--green); }
.tone-red .pill.big, .pill.tone-red { background: var(--red-bg); color: var(--red); }
.tone-yellow .pill.big, .pill.tone-yellow { background: var(--yellow-bg); color: var(--yellow); }
.tone-blue .pill.big, .pill.tone-blue { background: var(--blue-bg); color: var(--blue); }
.tone-orange .pill.big, .pill.tone-orange { background: var(--orange-bg); color: var(--orange); }
.meaning { font-size: 1.05rem; margin: .2rem 0 1rem; }
.since { color: var(--muted); font-size: .92rem; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .9rem; }
dl.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.ltr { direction: ltr; unicode-bidi: embed; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { background: var(--grey-bg); border-radius: 6px; padding: 0 .4rem; font-size: .82rem; font-family: ui-monospace, Consolas, monospace; direction: ltr; }
.cause { margin-top: .8rem; background: var(--red-bg); color: var(--red); border-radius: 8px; padding: .5rem .75rem; font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline h3 { font-size: .95rem; margin: 0 0 .6rem; color: var(--muted); }
.timeline li { position: relative; padding: 0 1.4rem .9rem 0; }
.timeline li::before {
  content: ""; position: absolute; right: .33rem; top: .45rem; bottom: -.45rem; width: 2px; background: var(--line);
}
.timeline li:last-child::before { display: none; }
.timeline li::after {
  content: ""; position: absolute; right: 0; top: .3rem; width: .7rem; height: .7rem; border-radius: 50%;
  background: #fff; border: 2px solid #9aa5b4;
}
.timeline li.current::after { background: var(--brand-2); border-color: var(--brand-2); }
.timeline li.tone-green::after { border-color: var(--green); }
.timeline li.tone-red::after { border-color: var(--red); }
.timeline li.current.tone-green::after { background: var(--green); }
.timeline li.current.tone-red::after { background: var(--red); }
.tl-when { color: var(--muted); font-size: .85rem; }
.tl-what { font-weight: 600; }
.tl-empty { color: var(--muted); font-size: .9rem; }

.empty {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; text-align: center;
}
.empty h2 { font-size: 1.3rem; }
.empty ul { text-align: start; display: inline-block; margin: .5rem 0 0; padding-inline-start: 1.2rem; color: var(--muted); }
.empty .try { font: inherit; background: none; border: 0; color: var(--brand-2); text-decoration: underline; cursor: pointer; padding: 0; }
.loading { display: flex; align-items: center; gap: .75rem; color: var(--muted); padding: 1rem; }

/* --- excel -------------------------------------------------------------------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  border: 2px dashed #b7c3d1; border-radius: 12px; padding: 1.6rem 1rem; text-align: center;
  cursor: pointer; background: #fafcfe; margin: 0;
}
.dropzone.drag { border-color: var(--brand-2); background: var(--blue-bg); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-title { font-weight: 700; color: var(--brand); }
.dz-sub { color: var(--muted); font-weight: 400; font-size: .9rem; direction: ltr; unicode-bidi: plaintext; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; }
.table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { border-bottom: 1px solid var(--line); padding: .45rem .6rem; text-align: start; white-space: nowrap; }
table.preview td, table.preview th { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table.preview th.colhead { cursor: pointer; background: #f3f6f9; color: var(--muted); font-weight: 600; }
table.preview .rownum { color: #98a2b3; background: #f8fafc; text-align: center; width: 1%; }
table.preview tr.is-header td { font-weight: 700; background: #eef3f8; }
table.preview .picked { background: #fff6d6 !important; }
table.preview th.picked { color: var(--ink); }
table.preview tr.before-header td { color: #98a2b3; }
.progress { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.progress > div:last-child { flex: 1; }
.bar { height: 8px; background: var(--grey-bg); border-radius: 99px; overflow: hidden; margin-top: .35rem; }
.bar span { display: block; height: 100%; width: 0; background: var(--brand-2); transition: width .2s; }
.bar.indeterminate span { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(120%); } to { transform: translateX(-300%); } }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--grey-bg); border-top-color: var(--brand-2);
  animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin: .75rem 0; }
.stat { background: #f7f9fb; border-radius: 10px; padding: .7rem .9rem; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .88rem; }
.status-counts { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 1rem; }

/* --- admin -------------------------------------------------------------------- */
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; align-items: end; }
.grid-form .btn { margin-bottom: .8rem; }
table.list th { background: #f3f6f9; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.list td.actions { display: flex; gap: .35rem; flex-wrap: wrap; white-space: normal; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; border-radius: 6px; padding: 0 .4rem; }
.badge.admin { background: var(--blue-bg); color: var(--blue); }
.badge.off { background: var(--grey-bg); color: var(--grey); }
.badge.lock { background: var(--red-bg); color: var(--red); }
.badge.pw { background: var(--yellow-bg); color: var(--yellow); }
td.detail { white-space: normal; max-width: 420px; font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }

.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100% - 2rem);
}

/* --- mobile ------------------------------------------------------------------- */
@media (max-width: 720px) {
  .topbar { padding: .55rem .8rem; gap: .5rem; }
  .usermenu { width: 100%; justify-content: flex-end; margin: 0; font-size: .85rem; }
  .tabs { width: 100%; order: 3; }
  .tabs a { padding: .4rem .6rem; font-size: .92rem; }
  main { padding: 1rem .75rem 3rem; }
  .card-body { grid-template-columns: 1fr; }
  .searchbar { flex-direction: column; }
  .searchbar .btn { width: 100%; }
  .pill.big { font-size: 1.35rem; }
}
