/* ===========================================================================
   Practice Tracker — visual design.
   One stylesheet, no framework. Mobile-first: the front desk works on phones
   as much as desktops.

   Palette: a deep violet primary with tinted neutrals. Purple carries the
   brand (top bar, primary actions, active states); everything else stays
   near-neutral so patient data reads clearly. Status colors stay outside the
   purple family so approved/denied remain instantly distinguishable.
   =========================================================================== */

:root {
  /* Brand */
  --violet-900: #2e1b4d;
  --violet-800: #3d2568;
  --violet-700: #4c2e82;
  --violet-600: #5d3a9e;   /* primary */
  --violet-500: #7350b8;
  --violet-300: #b9a3e0;
  --violet-100: #ece5f8;
  --violet-050: #f6f2fd;

  /* Neutrals, very slightly violet-tinted so they sit with the brand */
  --bg: #f7f5fb;
  --card: #ffffff;
  --ink: #241c33;
  --ink-soft: #4a4260;
  --muted: #6f6685;
  --line: #e4dff0;
  --line-strong: #d3cbe6;

  /* Status */
  --ok: #17795e;
  --ok-bg: #e6f5f0;
  --danger: #a3123c;
  --danger-bg: #fdeaf0;
  --warn: #8a5a00;
  --warn-bg: #fdf1de;

  --accent: var(--violet-600);
  --accent-ink: #ffffff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(46, 27, 77, .06), 0 1px 3px rgba(46, 27, 77, .04);
  --shadow-md: 0 2px 6px rgba(46, 27, 77, .08), 0 6px 16px rgba(46, 27, 77, .06);
  --shadow-lg: 0 12px 32px rgba(46, 27, 77, .18);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;   /* wide content scrolls in its own wrapper, never the page */
}
.hidden { display: none !important; }
a { color: var(--violet-600); }

/* ---- Sign-in gate ---- */
.gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(1100px 520px at 12% -10%, var(--violet-100), transparent 60%),
    radial-gradient(900px 460px at 105% 105%, #e9defb, transparent 55%),
    var(--bg);
}
.gate-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 2.75rem 2rem; max-width: 23rem; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: .9rem; align-items: center;
  box-shadow: var(--shadow-md);
}
.gate-card h1 { margin: 0; font-size: 1.45rem; letter-spacing: -.01em; }
.gate-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.gate-card .btn { margin-top: .3rem; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: .7rem;
  background: linear-gradient(100deg, var(--violet-800), var(--violet-600) 62%, var(--violet-500));
  color: #fff;
  padding: .6rem 1rem; position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 650; letter-spacing: -.01em; font-size: 1.02rem;
}
.brand img { filter: brightness(0) invert(1); opacity: .95; }
.company-picker {
  font: inherit; font-size: .92rem; padding: .34rem .6rem;
  border: 1px solid rgba(255, 255, 255, .28); border-radius: 999px;
  background: rgba(255, 255, 255, .14); color: #fff;
  max-width: 15rem; cursor: pointer;
}
.company-picker:hover { background: rgba(255, 255, 255, .22); }
.company-picker option { color: var(--ink); background: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .8rem; }
.whoami { color: rgba(255, 255, 255, .82); font-size: .85rem; }
.signout {
  color: #fff; font-size: .85rem; text-decoration: none; opacity: .85;
  border-bottom: 1px solid rgba(255, 255, 255, .35); padding-bottom: 1px;
}
.signout:hover { opacity: 1; }

/* ---- Tabs ---- */
.tabs {
  display: flex; gap: .3rem; padding: .55rem 1rem; flex-wrap: wrap;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.tab {
  border: 1px solid transparent; background: none; font: inherit; font-size: .92rem;
  padding: .42rem .85rem; cursor: pointer; color: var(--muted);
  border-radius: 999px; transition: background .12s, color .12s;
}
.tab:hover { background: var(--violet-050); color: var(--violet-700); }
.tab.active {
  background: var(--violet-100); border-color: var(--violet-300);
  color: var(--violet-800); font-weight: 600;
}

main { padding: 1.1rem 1rem 3rem; max-width: 78rem; margin: 0 auto; }

/* ---- Toolbar ---- */
.toolbar { display: flex; align-items: center; gap: .55rem; margin-bottom: .85rem; flex-wrap: wrap; }
.toolbar input[type="search"] {
  font: inherit; padding: .48rem .75rem; border: 1px solid var(--line-strong);
  border-radius: 999px; flex: 1 1 12rem; max-width: 21rem; background: var(--card);
  color: var(--ink); box-shadow: var(--shadow-sm);
}
.toolbar input[type="search"]:focus {
  outline: none; border-color: var(--violet-500);
  box-shadow: 0 0 0 3px var(--violet-100);
}
.chk { display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .9rem; cursor: pointer; }
.chk input { accent-color: var(--violet-600); width: 1rem; height: 1rem; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: .85rem; line-height: 1.5; }

/* ---- Buttons ---- */
.btn {
  font: inherit; font-size: .92rem; padding: .46rem .95rem; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid var(--line-strong); background: var(--card);
  color: var(--ink-soft); text-decoration: none; display: inline-block;
  transition: border-color .12s, background .12s, color .12s, box-shadow .12s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--violet-500); color: var(--violet-700); background: var(--violet-050); }
.btn.primary {
  background: var(--violet-600); border-color: var(--violet-600); color: var(--accent-ink);
  font-weight: 550;
}
.btn.primary:hover { background: var(--violet-700); border-color: var(--violet-700); color: #fff; }
.btn.danger { background: var(--card); border-color: #e6b9c8; color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn.subtle { border-color: transparent; background: none; box-shadow: none; color: var(--violet-600); }
.btn.subtle:hover { background: var(--violet-050); }
.btn.small { padding: .22rem .6rem; font-size: .83rem; box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--violet-500); outline-offset: 2px; }

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap { white-space: normal; min-width: 12rem; }
th {
  background: var(--violet-050); font-weight: 600; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--violet-700);
  position: sticky; top: 0;
}
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--violet-050); }
tbody tr.static { cursor: default; }
tbody tr.static:hover { background: none; }
tr:last-child td { border-bottom: none; }
td input[type="checkbox"] { accent-color: var(--violet-600); width: 1.05rem; height: 1.05rem; cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 2.5rem 0; }

/* Status chips */
.chip {
  display: inline-block; padding: .12rem .6rem; border-radius: 999px;
  font-size: .78rem; font-weight: 550; border: 1px solid var(--line-strong);
  background: var(--violet-050); color: var(--violet-700);
}
.chip.approved, .chip.done, .chip.received { border-color: #a9d9c9; background: var(--ok-bg); color: var(--ok); }
.chip.denied, .chip.expired { border-color: #eab6c6; background: var(--danger-bg); color: var(--danger); }
.chip.pending, .chip.submitted, .chip.open, .chip.scheduled, .chip.out {
  border-color: #e8cf9f; background: var(--warn-bg); color: var(--warn);
}

/* ---- Modals ---- */
dialog {
  border: 1px solid var(--line); border-radius: 16px; padding: 1.4rem;
  width: min(35rem, calc(100vw - 2rem)); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(46, 27, 77, .42); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 1rem; font-size: 1.15rem; letter-spacing: -.01em; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem .9rem; }
.fields label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--muted); font-weight: 550; }
.fields label.full { grid-column: 1 / -1; }
.fields input, .fields select, .fields textarea {
  font: inherit; font-size: .95rem; padding: .5rem .6rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--card); color: var(--ink); width: 100%;
}
.fields input:focus, .fields select:focus, .fields textarea:focus {
  outline: none; border-color: var(--violet-500); box-shadow: 0 0 0 3px var(--violet-100);
}
.meta { color: var(--muted); font-size: .8rem; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.modal-actions { display: flex; gap: .5rem; margin-top: 1.2rem; align-items: center; }
.error { color: var(--danger); margin: .7rem 0 0; font-size: .9rem; }

/* ---- History ---- */
.history-list { margin: 0; padding-left: 1.2rem; max-height: 55vh; overflow-y: auto; }
.history-list li { margin-bottom: .8rem; font-size: .9rem; }
.history-list .when { color: var(--muted); font-size: .78rem; }
.history-list .delta { display: block; color: var(--muted); font-size: .85rem; }
.history-list .delta b { color: var(--violet-700); }

/* ===========================================================================
   Admin — every section is its own tile: icon, title, subtitle, then content.
   Tiles auto-fit into columns so nothing has to be hunted for.
   =========================================================================== */
.admin-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(23rem, 100%), 1fr));
  align-items: start;
}
/* Grid and flex children default to min-width:auto, which lets a wide table
   push the whole page sideways instead of scrolling inside its own wrapper.
   Everything that can contain a table needs to be allowed to shrink. */
.admin-grid > *, .card, .card-head > div { min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.2rem; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.card.wide { grid-column: 1 / -1; }

.card-head { display: flex; align-items: flex-start; gap: .7rem; margin-bottom: .9rem; }
.card-icon {
  flex: none; width: 2.1rem; height: 2.1rem; border-radius: 10px;
  background: var(--violet-100); color: var(--violet-700);
  display: grid; place-items: center;
}
.card-icon svg { width: 1.15rem; height: 1.15rem; stroke: currentColor; fill: none;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.card-head h2 { margin: 0; font-size: 1.02rem; letter-spacing: -.01em; }
.card-head .hint { margin: .15rem 0 0; }
.card h3 { font-size: .9rem; margin: 1rem 0 .4rem; color: var(--ink-soft); }

.row-form { display: flex; gap: .5rem; margin-top: .8rem; flex-wrap: wrap; }
.row-form input, .row-form select {
  font: inherit; font-size: .92rem; padding: .45rem .6rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--card); color: var(--ink); flex: 1 1 8rem;
}
.row-form input:focus, .row-form select:focus {
  outline: none; border-color: var(--violet-500); box-shadow: 0 0 0 3px var(--violet-100);
}
.name-list { list-style: none; margin: 0; padding: 0; }
.name-list li {
  display: flex; align-items: center; gap: .5rem; padding: .5rem 0; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.name-list li:last-child { border-bottom: none; }
.name-list .name { flex: 1 1 10rem; font-weight: 550; font-size: .93rem; }
.name-list .hint { flex: 1 1 100%; }

/* ---- Module / location checkbox rows ---- */
.module-checks { display: flex; flex-wrap: wrap; gap: .45rem .9rem; margin-top: .7rem; }
.module-checks .chk {
  background: var(--violet-050); border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .75rem; color: var(--ink-soft); font-size: .88rem;
}
.module-checks .chk:hover { border-color: var(--violet-300); }

/* ---- Import ---- */
.import-box { max-height: 75vh; overflow-y: auto; }
.import-preview-h { font-size: .88rem; margin: 1.1rem 0 .45rem; color: var(--muted); }
#import-preview td, #import-preview th { font-size: .8rem; }
#import-file {
  font: inherit; font-size: .9rem; margin-top: .6rem; width: 100%;
  padding: .8rem; border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: var(--violet-050); cursor: pointer;
}
#import-result ul { margin: .35rem 0 0 1.2rem; padding: 0; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--violet-900); color: #fff; padding: .65rem 1.2rem;
  border-radius: 999px; font-size: .9rem; z-index: 50; max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 640px) {
  .fields { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .whoami { display: none; }
  main { padding: .8rem .7rem 2.5rem; }
  .company-picker { max-width: 9.5rem; }
}
