/* ==========================================================================
   Nexstart Admin — hand-written styles.
   Brand tokens from the live nexstart.io CSS.
   ========================================================================== */

:root {
  --paper: #fafaf8;
  --ink: #24252b;
  --muted: #68696f;
  --purple: #6550e8;
  --lilac: #e8e3fa;
  --line: #dededb;
  --mint: #d7eedc;
  --purple-hover: #5240cf;
  --purple-deep: #4530a7;
  --lilac-2: #ebe7f6;
  --lilac-3: #f0edf6;
  --lilac-4: #e5e0f8;
  --surface: #ffffff;
  --shadow-sm: 0 2px 4px #4c3e7420;
  --shadow-md: 0 12px 30px #5e41830a;
  --ring: 0 0 0 8px #ebe7f6, 0 0 0 9px #d4cbe8, 0 12px 24px #6550e824;

  --amber-bg: #faf0db;
  --amber-ink: #8a6417;
  --green-ink: #467450;
  --rose-bg: #f2e1dd;
  --rose-ink: #975e51;

  --radius-card: 16px;
  --radius-ctrl: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--purple); text-decoration: none; }
a:hover { color: var(--purple-hover); }

h1, h2, h3 {
  letter-spacing: -0.035em;
  color: var(--ink);
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Layout shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  grid-template-areas: "sidebar content";
  min-height: 100vh;
}

.topbar {
  display: none;
}

.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--lilac-3), var(--paper) 60%);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.04em;
  color: var(--ink);
  padding: 6px 6px 16px;
}
.brand:hover { color: var(--ink); }
.brand-mark {
  color: var(--purple);
  font-size: 18px;
  line-height: 1;
  transform: translateY(1px);
}
.brand-sub {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-left: 2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 14.5px;
  transition: background .15s ease;
}
.nav-item:hover { background: var(--lilac-2); color: var(--ink); }
.nav-item.is-active {
  background: var(--lilac);
  color: var(--purple-deep);
}
.nav-soon {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.nav-footer {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.who { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--lilac);
  color: var(--purple-deep);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.who-name { font-weight: 600; font-size: 14px; }
.logout {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
}
.logout:hover { color: var(--purple); }

.content {
  grid-area: content;
  padding: 36px clamp(20px, 4vw, 48px);
  max-width: 1120px;
  width: 100%;
}

/* ---------- Page header ---------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.045em;
}
.page-sub {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14.5px;
}
.back-link {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  display: inline-block;
  margin-bottom: 6px;
}
.back-link:hover { color: var(--purple); }

.soon-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--lilac-2);
  border-radius: 999px;
  padding: 3px 11px;
  vertical-align: middle;
  margin-left: 8px;
  letter-spacing: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14.5px;
  padding: 10px 18px;
  border-radius: var(--radius-ctrl);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--purple);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--purple-hover); color: #fff; }
.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost:hover { background: var(--lilac-3); color: var(--ink); }
.btn-block { width: 100%; }
.btn:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.card-title + .card-title { margin-top: 20px; }

/* ---------- Flash ---------- */
.flash {
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}
.flash-success { background: var(--mint); color: var(--green-ink); border-color: #bfe0c7; }
.flash-error   { background: var(--rose-bg); color: var(--rose-ink); border-color: #e6cbc4; }
.flash-info    { background: var(--lilac-2); color: var(--purple-deep); border-color: var(--lilac-4); }

/* ---------- Filter chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  font-size: 13.5px;
}
.chip:hover { border-color: var(--lilac-4); color: var(--ink); }
.chip.is-active { background: var(--lilac); border-color: var(--lilac-4); color: var(--purple-deep); }
.chip-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--paper);
  border-radius: 999px;
  padding: 0 7px;
  min-width: 20px;
  text-align: center;
}
.chip.is-active .chip-count { background: var(--surface); color: var(--purple-deep); }

/* ---------- Table ---------- */
.table-card { padding: 6px 6px; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--lilac-3);
  vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: none; }
.row-link { cursor: pointer; transition: background .12s ease; }
.row-link:hover { background: var(--lilac-3); }
.mono-link { font-weight: 700; letter-spacing: -0.01em; }
.cell-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
}
.badge-pending  { background: var(--lilac-2); color: var(--muted); border-color: var(--lilac-4); }
.badge-working  { background: var(--lilac); color: var(--purple-deep); border-color: var(--lilac-4); }
.badge-question { background: var(--amber-bg); color: var(--amber-ink); border-color: #ecdcb4; }
.badge-done     { background: var(--mint); color: var(--green-ink); border-color: #bfe0c7; }
.badge-error    { background: var(--rose-bg); color: var(--rose-ink); border-color: #e6cbc4; }

/* ---------- Empty state ---------- */
.empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  padding: 56px 32px;
  text-align: center;
  max-width: 560px;
  margin: 10px auto;
}
.empty-mark {
  width: 54px; height: 54px;
  border-radius: 16px;
  background: var(--lilac);
  color: var(--purple);
  font-size: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
.empty h2 { font-size: 19px; font-weight: 750; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 auto 20px; max-width: 420px; }

/* ---------- Forms ---------- */
.form-card { padding: 26px 28px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 22px;
  margin-bottom: 4px;
}
.field { margin-bottom: 18px; display: flex; flex-direction: column; }
/* display:flex would otherwise override the hidden attribute */
.field[hidden], [hidden] { display: none !important; }
.field label {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--ink);
}
.req { color: var(--purple); }
.field-help { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.field-error { color: var(--rose-ink); font-size: 12.5px; margin: 6px 0 0; font-weight: 600; }

input[type="text"], input[type="url"], input[type="password"],
input[type="date"], textarea, select {
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-ctrl);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 1px 0 var(--purple);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2368696f' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.tag-internal {
  font-size: 11px;
  font-weight: 700;
  color: var(--amber-ink);
  background: var(--amber-bg);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 4px;
  letter-spacing: 0.02em;
}
.field-internal textarea { background: #fcfbf7; }
.longtext-internal {
  background: #fcfbf7;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--lilac-3);
  padding-top: 20px;
}

/* ---------- Detail page ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 22px;
  align-items: start;
}
.longtext { white-space: normal; color: var(--ink); margin: 0 0 6px; }
.muted { color: var(--muted); }

.meta { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.meta dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.meta dd { margin: 0; font-size: 14px; font-weight: 500; word-break: break-word; }

/* Callouts */
.callout {
  border-radius: var(--radius-card);
  padding: 20px 22px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}
.callout h3 { font-size: 16px; margin-bottom: 8px; }
.callout-body { margin: 0; }
.callout-question { background: var(--amber-bg); border-color: #ecdcb4; color: var(--amber-ink); }
.callout-question h3 { color: var(--amber-ink); }
.callout-error { background: var(--rose-bg); border-color: #e6cbc4; color: var(--rose-ink); }
.callout-error h3 { color: var(--rose-ink); }
.callout-progress { background: var(--lilac-3); border-color: var(--lilac-4); color: var(--ink); }
.callout-progress h3 { color: var(--purple-deep); }

.answer-form { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.answer-form label { font-weight: 600; font-size: 14px; color: var(--ink); }
.answer-form textarea { background: var(--surface); }
.answer-form .btn { align-self: flex-start; }

.agent-note {
  margin-top: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
}

/* Document links */
.result-card { border-color: #bfe0c7; }
.doc-links { display: grid; gap: 10px; margin-bottom: 4px; }
.doc-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--paper);
  transition: border-color .15s ease, background .15s ease;
}
.doc-link:hover { border-color: var(--purple); background: var(--lilac-3); }
.doc-link-label { font-weight: 700; color: var(--ink); }
.doc-link-url { font-size: 12.5px; color: var(--muted); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 7px; top: 16px; bottom: 0;
  width: 1px;
  background: var(--line);
}
.timeline-dot {
  width: 14px; height: 14px;
  border-radius: 999px;
  background: var(--lilac);
  border: 2px solid var(--purple);
  margin-top: 3px;
}
.timeline-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.timeline-event { font-weight: 650; font-size: 14px; }
.timeline-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.timeline-msg { margin: 4px 0 2px; color: var(--ink); font-size: 13.5px; }
.timeline-actor { color: var(--muted); font-size: 12px; }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(1100px 500px at 50% -10%, var(--lilac-3), transparent 70%),
    var(--paper);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 34px 32px;
}
.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.04em;
  margin-bottom: 22px;
}
.login-title { font-size: 23px; font-weight: 800; letter-spacing: -0.04em; }
.login-help { color: var(--muted); margin: 6px 0 22px; font-size: 14px; }
.login-card .btn-block { margin-top: 6px; }

/* ---------- Responsive ---------- */
.nav-toggle { display: none; }
.hamburger { display: none; }
.brand-desktop { display: inline-flex; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "content"; }
  .topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--lilac-3);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
  }
  .brand-desktop { display: none; }
  .sidebar {
    grid-area: content;
    position: fixed;
    inset: 56px 0 auto 0;
    height: auto;
    z-index: 15;
    border-right: none;
    border-bottom: 1px solid var(--line);
    display: none;
    background: var(--paper);
  }
  .nav-toggle:checked ~ .sidebar { display: flex; }
  .sidebar .brand { display: none; }
  .content { grid-area: content; padding: 24px 18px; }
  .hamburger {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    padding: 6px;
  }
  .hamburger span {
    width: 22px; height: 2px;
    background: var(--ink);
    border-radius: 2px;
  }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

@media (max-width: 560px) {
  .cell-sub { display: none; }
}
