/* ─────────────────────────────────────────────────────────────────────────
   AAC Made Easy — global design tokens.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Spacing */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* Radii */
  --r-sm: 6px;  --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;

  /* Type scale */
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 15px;
  --fs-lg: 17px; --fs-xl: 20px; --fs-2xl: 26px; --fs-3xl: 32px;

  /* Colours — modern, professional, cool-neutral */
  --bg:            #F6F7FA;
  --bg-elevated:   #FFFFFF;
  --bg-sunken:     #ECEEF3;
  --bg-tinted:     #F1F3F9;
  --ink:           #0E1525;
  --ink-soft:      #4D5870;
  --ink-faint:     #8A93A6;
  --border:        #E2E5EC;
  --border-strong: #CDD2DC;
  --border-soft:   #EDF0F4;
  --accent:        #5546FF;
  --accent-deep:   #3D32D1;
  --accent-soft:   #EEEBFF;
  --accent-ink:    #2A21A8;
  --primary:       #0E1525;
  --primary-hover: #1F2A40;
  --primary-ink:   #FFFFFF;
  --danger:        #D63A3A;
  --danger-soft:   #FDEBEB;
  --danger-ink:    #8E1F1F;
  --success:       #10925B;
  --success-soft:  #DCF1E5;
  --info:          #2965CC;
  --info-soft:     #E0ECFB;
  --warning:       #C46A1A;
  --warning-soft:  #FCEDD8;

  /* Elevation */
  --shadow-sm:  0 1px 2px rgba(15,21,37,.04), 0 1px 1px rgba(15,21,37,.02);
  --shadow-md:  0 4px 12px rgba(15,21,37,.06), 0 2px 4px rgba(15,21,37,.04);
  --shadow-lg:  0 12px 32px rgba(15,21,37,.08), 0 4px 12px rgba(15,21,37,.04);
  --shadow-pop: 0 24px 60px rgba(15,21,37,.16), 0 6px 18px rgba(15,21,37,.08);

  /* Controls — single source of truth */
  --ctrl-h-sm:   32px;
  --ctrl-h:      40px;
  --ctrl-h-lg:   48px;
  --ctrl-px-sm:  10px;
  --ctrl-px:     12px;
  --ctrl-px-lg:  16px;
  --focus-color: #5546FF;
  --focus-ring:  0 0 0 3px rgba(85,70,255,.22);

  /* Typography */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, system-ui, sans-serif;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Reset / baseline */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
html { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-base);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

/* Anything overly long that we accept will wrap rather than push the page
   sideways. The portal has plenty of hashes / paths / shared links. */
.kbd, code { word-break: break-all; max-width: 100%; }

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: 1.25; color: var(--ink); }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.015em; }
h2 { font-size: var(--fs-xl); letter-spacing: -0.005em; }
h3 { font-size: var(--fs-lg); }
p  { margin: 0; }
hr { border: none; border-top: 1px solid var(--border); margin: var(--s-5) 0; }

.muted        { color: var(--ink-soft); font-size: var(--fs-sm); }
.muted-strong { color: var(--ink-soft); font-size: var(--fs-base); font-weight: 500; }
.dim          { color: var(--ink-faint); font-size: var(--fs-sm); }

/* ────────────────────────────────────────────────────────────────
   FORM CONTROLS — UNIFORM SIZE, PERFECT ALIGNMENT
   ──────────────────────────────────────────────────────────────── */

/* Every text-like control is exactly the same height and uses the same
   internal padding. Browsers' UA stylesheets are aggressively reset. */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="time"],
input:not([type]),
select,
textarea {
  width: 100%;
  height: var(--ctrl-h);
  min-height: var(--ctrl-h);
  max-height: var(--ctrl-h);
  padding: 0 var(--ctrl-px);
  margin: 0;
  font-family: inherit;
  font-size: var(--fs-base);
  line-height: var(--ctrl-h);
  color: var(--ink);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  -webkit-appearance: none;
  appearance: none;
}
textarea {
  height: auto; min-height: 88px; max-height: none;
  padding: 10px var(--ctrl-px); line-height: 1.5;
}
input[type="color"] {
  width: 100%; height: var(--ctrl-h); padding: 3px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--r-md);
  cursor: pointer; box-shadow: var(--shadow-sm);
}

input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  border-color: var(--focus-color);
  box-shadow: var(--focus-ring);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg-sunken); color: var(--ink-faint);
  cursor: not-allowed;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%234D5870' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px; cursor: pointer;
}

input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; min-height: 18px; max-height: 18px;
  accent-color: var(--accent); vertical-align: middle; margin: 0;
  cursor: pointer;
}

label { font-family: inherit; }

/* Field: label on top, control below — strict alignment via grid. */
.field {
  display: grid;
  grid-template-rows: 20px auto;
  gap: var(--s-1);
  min-width: 0;
}
.field-label, label.fld {
  display: flex; align-items: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  line-height: 1;
  height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-hint { font-size: var(--fs-xs); color: var(--ink-faint); }

/* Form grid: any number of fields, all the same height, perfectly aligned. */
.form-grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 600px) {
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
}

/* Inline field row — label + control on one line. */
.form-stack { display: flex; flex-direction: column; gap: var(--s-4); }

/* ────────────────────────────────────────────────────────────────
   BUTTONS — single source of truth, all heights aligned to controls
   ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: var(--ctrl-h);
  min-height: var(--ctrl-h);
  padding: 0 var(--ctrl-px-lg);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease, box-shadow 120ms ease;
  white-space: nowrap;
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.btn:active   { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn.sm  { height: var(--ctrl-h-sm); min-height: var(--ctrl-h-sm); padding: 0 var(--ctrl-px); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.lg  { height: var(--ctrl-h-lg); min-height: var(--ctrl-h-lg); padding: 0 var(--s-6); font-size: var(--fs-md); }
.btn.block { width: 100%; }

.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn.accent  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn.ghost   { background: var(--bg-elevated); color: var(--ink); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg-sunken); border-color: var(--border-strong); }

.btn.subtle  { background: transparent; color: var(--ink-soft); box-shadow: none; }
.btn.subtle:hover { background: var(--bg-sunken); color: var(--ink); }

.btn.danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #BC3030; border-color: #BC3030; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger-soft); box-shadow: none; }
.btn.danger-ghost:hover { background: var(--danger-soft); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ctrl-h); height: var(--ctrl-h);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; cursor: pointer; color: var(--ink);
  font-size: 17px; padding: 0;
  transition: background 120ms ease, border-color 120ms ease;
}
.iconbtn:hover { background: var(--bg-sunken); }
.iconbtn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ── Cards / sections ─────────────────────────────────────────── */
.card, .section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  box-shadow: var(--shadow-sm);
}
.card + .card, .section + .section { margin-top: var(--s-4); }

.card-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4);
  margin-bottom: var(--s-5);
}
.card-header .title h2 { margin: 0; }
.card-header .title p  { margin-top: var(--s-1); color: var(--ink-soft); font-size: var(--fs-sm); }
.card-header .actions  { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ── Lists ────────────────────────────────────────────────────── */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.list li {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); min-height: 60px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.list li .meta { color: var(--ink-soft); font-size: var(--fs-sm); margin-top: 2px; }
.list li.empty { color: var(--ink-soft); justify-content: center; font-size: var(--fs-sm); background: transparent; border-style: dashed; min-height: 80px; }

/* ── Pills / badges ───────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  border-radius: var(--r-full);
  background: var(--bg-sunken); color: var(--ink-soft);
  border: 1px solid var(--border);
}
.pill.accent  { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.pill.danger  { background: var(--danger-soft); color: var(--danger-ink); border-color: transparent; }
.pill.success { background: var(--success-soft); color: var(--success);   border-color: transparent; }
.pill.info    { background: var(--info-soft); color: var(--info);         border-color: transparent; }
.pill.warning { background: var(--warning-soft); color: var(--warning);   border-color: transparent; }

/* ── Messages ─────────────────────────────────────────────────── */
.msg-err  { color: var(--danger);  font-size: var(--fs-sm); min-height: 20px; padding-top: 4px; }
.msg-ok   { color: var(--success); font-size: var(--fs-sm); min-height: 20px; padding-top: 4px; }

/* ── Flex utils ───────────────────────────────────────────────── */
.row    { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.right   { justify-content: flex-end; }
.row.tight   { gap: var(--s-2); }
.grow   { flex: 1; }
.stack  { display: flex; flex-direction: column; gap: var(--s-3); }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); } .mt-6 { margin-top: var(--s-6); }

/* ── Modal ────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  background: rgba(14,21,37,.45);
  backdrop-filter: blur(4px);
  padding: var(--s-6);
}
.modal.show { display: flex; }
.modal-card {
  background: var(--bg-elevated);
  border-radius: var(--r-xl);
  padding: var(--s-6);
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-pop);
  max-height: calc(100vh - 48px); overflow: auto;
}
.modal-card.wide { max-width: 720px; }
.modal-card > h3 { margin: 0 0 var(--s-3); }
.modal-card > .muted { margin-bottom: var(--s-4); }

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
