/* Partronics office portal. Visual identity taken from partronics.in (css/base.css,
   components/header.css, components/footer.css): rose brand gradient, near-black header
   and footer bands, slate neutrals, 8/16 radii. The public site is dark only and
   loads Outfit / Plus Jakarta Sans from Google Fonts; the portal is light by default with
   a dark block that matches the public tokens, and uses a system font stack so that
   nothing is fetched from the network. */

/* ---------- Tokens ---------- */
:root {
  /* The parts of a control the page cannot paint - a select's drop-down list, a checkbox tick,
     a scrollbar - are drawn by the browser, and it draws them light unless it is told the page
     follows both schemes. Without this the dark theme's near-white option text lands on the
     browser's white list and cannot be read. */
  color-scheme: light dark;

  /* Brand */
  --primary: #e11d48;
  --primary-hover: #be123c;
  /* The public gradient is #f43f5e -> #e11d48; shifted one stop darker so white button
     labels clear WCAG AA (4.5:1) instead of 3.3:1. Same rose, same direction. */
  --primary-gradient: linear-gradient(135deg, #e11d48 0%, #be123c 100%);
  --on-primary: #ffffff;
  --link: #be123c;

  /* Neutrals */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --panel: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;

  /* The header and footer bands keep the public site's near-black. */
  --band: #0b1220;
  --band-line: rgba(255, 255, 255, 0.1);
  --band-ink: #f8fafc;
  --band-muted: #9ca3af;
  --band-nav: #d1d5db;
  --band-hover: rgba(255, 255, 255, 0.08);

  /* Status */
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --ok-tint: #e7f6ed;
  --bad-tint: #fdeaea;

  /* Type */
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-head: "Segoe UI Variable Display", "Segoe UI Semibold", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Courier New", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-h1: clamp(24px, 3.4vw, 30px);

  /* Shape and rhythm */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-full: 9999px;
  --gap: 16px;
  --page-width: 1180px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --focus: 0 0 0 3px rgba(244, 63, 94, 0.28);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

/* The pages hide panels and cards with the hidden attribute; a class that sets display
   (.field, .form-row, .card-actions) would otherwise win over the browser default. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-head);
  color: var(--ink);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

h1 { font-size: var(--fs-h1); font-weight: 700; line-height: 1.2; }
h2 { font-size: var(--fs-lg); font-weight: 700; }
h3 { font-size: var(--fs-md); font-weight: 700; margin-top: var(--gap); }

p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

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

code {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 1px 5px;
}

img { max-width: 100%; display: block; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Layout ---------- */
.wrap {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--gap);
}

main { padding: 24px 0 32px; }

/* Header: the public site's dark bar, brand lockup on the left, action on the right. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--band);
  color: var(--band-ink);
  border-bottom: 1px solid var(--band-line);
}

.site-header a { color: var(--band-ink); text-decoration: none; }

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--gap);
  min-height: 68px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.brand-logo img { width: 90%; height: 90%; object-fit: contain; }
.brand:hover .brand-logo { border-color: #f43f5e; box-shadow: 0 0 14px rgba(244, 63, 94, 0.45); }

.brand-title {
  display: block;
  font-family: var(--font-head);
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.brand-sub {
  display: block;
  color: var(--band-muted);
  font-size: var(--fs-xs);
  letter-spacing: 0.055em;
  text-transform: uppercase;
  line-height: 1.3;
}

.header-action {
  border: 1px solid var(--band-line);
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 7px 15px;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.header-action:hover { background: var(--band-hover); border-color: rgba(255, 255, 255, 0.24); }

/* Portal nav: a second header row, the same markup on every portal page. */
.nav-bar { border-top: 1px solid rgba(255, 255, 255, 0.08); }

.portal-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
  min-height: 46px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.portal-nav a {
  color: var(--band-nav);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.portal-nav a:hover { color: #fff; background: var(--band-hover); text-decoration: none; }

.portal-nav a.here {
  color: #fff;
  background: rgba(244, 63, 94, 0.16);
  box-shadow: inset 0 -2px 0 var(--primary);
}

/* Footer: the public site's dark band, cut down to a brand line and two links. */
.site-footer {
  margin-top: auto;
  background: #05060a;
  border-top: 1px solid var(--band-line);
  color: var(--band-muted);
  font-size: var(--fs-sm);
  padding: 22px 0;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
}

.footer-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.footer-brand .brand-logo { width: 38px; height: 38px; }
.footer-name { display: block; color: var(--band-ink); font-weight: 600; }
.footer-sub { display: block; color: var(--band-muted); font-size: var(--fs-xs); }

.footer-links { display: flex; gap: 20px; flex-wrap: wrap; }
.site-footer a { color: var(--band-nav); }
.site-footer a:hover { color: #fff; text-decoration: none; }

/* ---------- Cards and grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: var(--gap);
}

.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Cards in a row are one height, and whatever they end with lines up along the bottom. Letting
   each card stop where its own text runs out leaves a row of ragged boxes and a hole beside the
   short one. */
.grid .card {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}

.grid .card > .card-actions:last-child { margin-top: auto; }
.grid-wide { grid-column: 1 / -1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-top: var(--gap);
  padding: var(--gap);
}

.count {
  font-family: var(--font-head);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--primary);
  margin: 0 0 4px;
}

.muted { color: var(--muted); }
.error { color: var(--bad); font-weight: 600; margin: 8px 0 0; }
.ok-line { color: var(--ok); font-weight: 600; margin: 8px 0 0; }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--primary-gradient);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: var(--on-primary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  padding: 9px 18px;
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(225, 29, 72, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.button:hover {
  color: var(--on-primary);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(225, 29, 72, 0.32);
}

button.button { cursor: pointer; font-size: var(--fs-sm); padding: 7px 14px; }
button.button[disabled] { opacity: .55; cursor: default; transform: none; box-shadow: none; }

/* Row-level actions, and anything secondary beside a primary, stay quiet: the public site's
   ghost button. Two rose buttons side by side give the eye nothing to choose between. */
td .button,
.button-quiet,
.row-actions .button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--link);
  box-shadow: none;
}

td .button:hover,
.button-quiet:hover,
.row-actions .button:hover {
  background: var(--panel);
  border-color: var(--primary);
  color: var(--primary-hover);
  transform: none;
  box-shadow: none;
}

.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* The public download page: one file, one button, nothing else to look at. */
.wrap-narrow { max-width: 620px; }
.download-file { font-family: var(--font-mono); font-size: var(--fs-md); font-weight: 600; word-break: break-all; margin-bottom: 4px; }
.download-foot { border-top: 1px solid var(--line); font-size: var(--fs-xs); margin-top: var(--gap); padding-top: 12px; }

/* Who is signed in, in the corner of every page: the name, and the roles under it small. */
.header-user { display: flex; align-items: center; gap: 14px; }

.who { display: flex; flex-direction: column; line-height: 1.25; text-align: right; min-width: 0; }
.who-name { color: var(--band-ink); font-size: var(--fs-sm); font-weight: 600; }
.who-roles { color: var(--band-muted); font-size: var(--fs-xs); }

@media (max-width: 520px) {
  .who { display: none; }
}

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; }

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}

th {
  background: var(--panel);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel); }

/* Tables keep their columns and scroll inside the card instead of widening the page. */
.scroll-x {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.scroll-x table { min-width: 460px; }

/* ---------- Badges and status ---------- */
.badge {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 11px;
}

.badge-ok { background: var(--ok-tint); border-color: rgba(21, 128, 61, 0.28); color: var(--ok); }
.badge-bad { background: var(--bad-tint); border-color: rgba(185, 28, 28, 0.28); color: var(--bad); }

.status { font-weight: 600; }
.status-active { color: var(--ok); }
.status-disabled { color: var(--muted); }
.status-expired { color: var(--bad); }
.status-pending { color: var(--warn); }
.status-rejected { color: var(--bad); }
.status-suspended { color: var(--warn); }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
  outline: none;
}

/* Every platform draws its own arrow on a select - on Windows a small hard triangle that matches
   nothing else here - and none of them follow the page. One chevron, drawn the same everywhere,
   with the padding to keep a long option from running underneath it. */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%23475569' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px 8px;
  padding-right: 34px;
  cursor: pointer;
}

select:disabled, input:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }

/* The drop-down list is painted from the select's own background-color, not from the page. A
   translucent one composites over the browser's white and the list comes out white, whatever
   color-scheme says - which in the dark theme puts near-white option text on white. So the
   colour here is opaque, and the options carry it too. */
option { background-color: var(--surface); color: var(--ink); }

input::placeholder, textarea::placeholder { color: #94a3b8; }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }

/* A checkbox reads as one line: the box, then what it means. The stacked label the other fields
   use leaves the box orphaned under its own caption. */
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.3;
  min-height: 34px;
}

.check input[type="checkbox"] { flex: 0 0 auto; margin: 0; }
.check span { color: var(--ink); }
.check:has(input:disabled) { cursor: not-allowed; opacity: 0.55; }

/* A checkbox that sits in a form-row beside text fields: same flex basis as its neighbours, but
   laid out as a check rather than a stacked label. */
.check-field { display: flex; align-items: center; gap: 8px; }
.check-field > span { display: inline; margin-bottom: 0; color: var(--ink); font-size: 14px; font-weight: 400; }
.check-field input[type="checkbox"] { flex: 0 0 auto; margin: 0; }
.check-field:has(input:disabled) { cursor: not-allowed; opacity: 0.55; }

/* Several related checkboxes: a column-filling grid rather than a ragged row. */
.checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 2px 16px;
  margin-bottom: 12px;
}
input[type="file"] { padding: 6px 8px; }
textarea { min-height: 120px; resize: vertical; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; }
.field-narrow { max-width: 220px; }

/* Downloads: the minutes box sits in the row beside its Link button. */
td.actions { white-space: nowrap; }
td.actions .minutes { width: 90px; display: inline-block; }

.form-row { display: flex; gap: var(--gap); flex-wrap: wrap; }
.form-row .field { flex: 1 1 180px; margin-bottom: 12px; min-width: 0; }

.roles-pick label { margin-right: 12px; white-space: nowrap; }

/* A flex item's automatic minimum is an input's default width, which overflows a phone;
   min-width 0 lets the boxes actually shrink. */
.node-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.node-row input, .node-row select { min-width: 0; }
.node-row .node-name { flex: 1 1 130px; }
.node-row .node-role { flex: 2 1 160px; }

/* ---------- Monospace boxes ---------- */
/* The settings overlay is edited as JSON, so it gets a monospace box that does not wrap. */
.json-box {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.5;
  min-height: 260px;
  overflow: auto;
  tab-size: 2;
  white-space: pre;
}

.token-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Page bits ---------- */
.fields { margin: 0; }
.fields div { border-bottom: 1px solid var(--line); display: flex; gap: var(--gap); padding: 7px 0; }
.fields div:last-child { border-bottom: 0; }
.fields dt { color: var(--muted); flex: 0 0 140px; font-size: 14px; font-weight: 600; }
.fields dd { margin: 0; font-size: 14px; word-break: break-word; }

/* Download kits: a heading and a plain file list per kit. */
#kits-list ul { list-style: none; margin: 0 0 var(--gap); padding: 0; display: grid; gap: 6px; }
#kits-list li { display: flex; gap: 8px; flex-wrap: wrap; font-size: 14px; }

/* Firmware page: the drop target for .pfw files, the files picked so far, the check warnings. */
.drop-zone {
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  padding: 24px;
  text-align: center;
  transition: border-color 0.2s ease;
}

.drop-zone.over { border-color: var(--primary); }
.drop-zone input[type="file"] { width: auto; margin: 0 auto; }

.file-list { list-style: none; margin: 0 0 var(--gap); padding: 0; display: grid; gap: 6px; }
.file-list li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }

.warnings { color: var(--warn); font-weight: 600; margin: 8px 0 0; padding-left: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  :root { --gap: 12px; }

  .header-inner { min-height: 60px; }
  .brand-logo { width: 42px; height: 42px; }
  .brand-title { font-size: var(--fs-md); }
  .brand-sub { font-size: 11px; }
  .portal-nav a { padding: 6px 10px; font-size: 13px; }
  .card { padding: 16px; }
  .footer-inner { justify-content: flex-start; }
  .form-row .field { flex-basis: 100%; }
  .field-narrow { max-width: none; }
}

/* ---------- Dark ---------- */
/* partronics.in is dark only; these are its own tokens, with the text colours lifted to
   stay readable on the card background. */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #f43f5e;
    --primary-hover: #e11d48;
    --link: #fda4af;

    --bg: #05060a;
    --surface: #111827;
    --panel: #0c1019;
    --ink: #f8fafc;
    --muted: #a3b1c2;
    --line: rgba(255, 255, 255, 0.1);

    --band: rgba(7, 10, 18, 0.98);

    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #fb7185;
    --ok-tint: rgba(34, 197, 94, 0.14);
    --bad-tint: rgba(244, 63, 94, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  }

  h1, h2, h3 { color: #ffffff; }

  input, textarea { background-color: rgba(255, 255, 255, 0.04); border-color: rgba(255, 255, 255, 0.14); }

  /* What rgba(255,255,255,0.04) composites to over a card, written out: the closed control looks
     the same as the inputs beside it, and the list it opens is legible. */
  select, option { background-color: #1b2130; color: var(--ink); }
  select { border-color: rgba(255, 255, 255, 0.14); }
  select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.75 6 6.25 11 1.75' fill='none' stroke='%23a3b1c2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
  input::placeholder, textarea::placeholder { color: #7b8794; }

  th { background: rgba(255, 255, 255, 0.03); }
  tbody tr:hover td { background: rgba(255, 255, 255, 0.03); }

  td .button,
  .button-quiet,
  .row-actions .button {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--line);
    color: var(--link);
  }

  td .button:hover,
  .button-quiet:hover,
  .row-actions .button:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

  .badge-ok { border-color: rgba(34, 197, 94, 0.32); color: #4ade80; }
  .badge-bad { border-color: rgba(244, 63, 94, 0.32); color: #fb7185; }

  code { background: rgba(255, 255, 255, 0.05); }
}
