/* Design tokens and base element styles. Every tool loads this first and does
   not redefine colours or the type scale. Light only for now; dark mode is a
   second :root block later. */

:root {
  color-scheme: light;

  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --line:      #d8dde5;
  --line-2:    #9aa4b2;
  --text:      #12161c;
  --text-2:    #5b6673;
  --accent:    #1a5fd0;
  --accent-2:  #12489f;
  --accent-bg: #e9f1fd;
  --ok:        #0a7d4f;
  --warn:      #a8630a;
  --bad:       #c23a34;
  --ok-bg:     #e7f6ee;
  --warn-bg:   #fdf1de;
  --bad-bg:    #fdeceb;

  --radius:    10px;
  --radius-in: 8px;
  --shadow:    0 6px 18px rgba(20, 30, 45, .08);
  --shadow-lg: 0 12px 32px rgba(20, 30, 45, .12);

  --step:      4px;
  --maxw:      1180px;

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;

  font-family: var(--font);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { background: var(--bg); overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img, svg, canvas { max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; letter-spacing: -.01em; font-weight: 650; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }
code, kbd, samp { font-family: var(--mono); font-size: .92em; }
small { font-size: .82rem; }

:focus-visible { outline: 3px solid rgba(26, 95, 208, .35); outline-offset: 2px; border-radius: 4px; }

::selection { color: #fff; background: var(--accent); }

.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: calc(var(--step) * 4); }
.row { display: flex; gap: calc(var(--step) * 2); align-items: center; flex-wrap: wrap; }

/* Buttons */
button, input, select, textarea { font: inherit; color: inherit; }
button:not(:disabled), select:not(:disabled),
input[type="checkbox"]:not(:disabled), label { cursor: pointer; }

.btn, .btn-primary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  max-width: 100%;
  padding: 8px 16px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  overflow-wrap: break-word;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px rgba(26, 95, 208, .18);
}
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { border-color: #e6b1ad; color: var(--bad); background: var(--surface); }
.btn-danger:hover { background: var(--bad-bg); }
.btn:disabled, .btn-primary:disabled, .btn-danger:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn svg, .btn-primary svg, .btn-danger svg { width: 17px; height: 17px; flex: 0 0 auto; }

.btn-sm { min-height: 34px; padding: 5px 12px; font-size: .9rem; }

.link-button {
  border: 0;
  padding: 4px 2px;
  background: none;
  color: var(--accent-2);
  font-weight: 600;
  font-size: .88rem;
}
.link-button:hover { text-decoration: underline; }

/* Form fields */
.field { display: grid; gap: 5px; }
.field > span, .field > label { font-size: .78rem; font-weight: 650; color: var(--text-2); }
.field em { color: var(--bad); font-style: normal; }

input[type="text"], input[type="search"], input[type="number"], input[type="date"],
input[type="email"], input[type="url"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-in);
  background: var(--surface);
  color: var(--text);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; font-family: var(--mono); }
input:hover, select:hover, textarea:hover { border-color: #6f7c8d; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(26, 95, 208, .14);
}
.field-help { font-size: .76rem; color: var(--text-2); line-height: 1.4; }
.field-help.warn { color: var(--warn); font-weight: 600; }

.check { display: inline-flex; align-items: flex-start; gap: 9px; font-size: .9rem; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); }

/* Surfaces */
.card, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.card { padding: calc(var(--step) * 4); }
.panel { overflow: hidden; }
.panel > header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel > header h2, .panel > header h3 { margin: 0; }
.panel > .body { padding: 16px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: .74rem;
  font-weight: 650;
}
.pill.ok { color: var(--ok); border-color: #a9d8c2; background: var(--ok-bg); }
.pill.warn { color: var(--warn); border-color: #ecc78d; background: var(--warn-bg); }
.pill.bad { color: var(--bad); border-color: #e6b1ad; background: var(--bad-bg); }

.note {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .86rem;
}
.note.ok { border-color: #a9d8c2; background: var(--ok-bg); }
.note.warn { border-color: #ecc78d; background: var(--warn-bg); }
.note.bad { border-color: #e6b1ad; background: var(--bad-bg); }

/* Tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th {
  position: sticky;
  top: 0;
  padding: 8px 10px;
  background: #eef1f5;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-2);
}
table.data td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #f5f8fc; }

/* Drop zone */
.dropzone {
  display: grid;
  place-items: center;
  min-height: 200px;
  padding: 24px;
  border: 2px dashed var(--line-2);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  transition: border-color .14s, background .14s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-bg); }
.dropzone p { max-width: 46ch; color: var(--text-2); }

/* Toast */
.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 340px;
  padding: 11px 14px;
  border-radius: var(--radius-in);
  background: #1b2430;
  color: #fff;
  font-size: .84rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* Error banner */
.error-banner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  margin-bottom: 16px;
  padding: 13px 15px;
  border: 1px solid #e6b1ad;
  border-left: 4px solid var(--bad);
  border-radius: var(--radius-in);
  background: var(--bad-bg);
}
.error-banner svg { width: 19px; height: 19px; margin-top: 1px; fill: none; stroke: var(--bad); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.error-banner strong { display: block; font-size: 1rem; }
.error-banner p { margin: 3px 0 0; font-size: .84rem; line-height: 1.5; }
.error-banner .link-button { color: var(--bad); }

/* Dialog */
.dialog-back {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 20, 28, .4);
}
.dialog {
  width: min(440px, 100%);
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.dialog h2 { font-size: 1.15rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 460px) {
  body { font-size: 14px; }
  .error-banner { grid-template-columns: auto 1fr; }
  .error-banner .link-button { grid-column: 1 / -1; justify-self: end; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn, .dialog-actions .btn-primary, .dialog-actions .btn-danger { width: 100%; }
}
