/* ===========================================================================
   Telesis Portal — Design System
   Office 365 inspired: sidebar + topbar + content area with cards.
   Shared by /admin and /user.
=========================================================================== */

:root {
  --brand: var(--brand-primary, #2563eb);
  --brand-strong: #1e40af;
  --brand-soft: rgba(37, 99, 235, 0.08);
  --brand-text-on: #ffffff;

  --bg:           #f3f5f9;
  --bg-card:      #ffffff;
  --bg-side:      #1f2937;
  --bg-side-acc:  #111827;
  --bg-topbar:    #ffffff;
  --bg-elevated:  #f8fafc;

  --ink:          #0f172a;
  --ink-soft:     #475569;
  --ink-mute:     #94a3b8;
  --ink-on-side:  #e5e7eb;
  --ink-on-side-mute: #94a3b8;

  --rule:         #e2e8f0;
  --rule-soft:    #f1f5f9;

  --green:  #10b981;
  --amber:  #f59e0b;
  --red:    #ef4444;
  --purple: #8b5cf6;
  --blue:   #3b82f6;
  --cyan:   #06b6d4;
  --pink:   #ec4899;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --sidebar-w: 260px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button { font-family: inherit; }

code {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 12px;
  background: var(--rule-soft);
  padding: 2px 5px;
  border-radius: 4px;
}

/* ─────────────────────────────────────────────
   App shell
───────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "side topbar"
    "side main";
  height: 100vh;
  transition: grid-template-columns .2s ease;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ─────────────────────────────────────────────
   Sidebar
───────────────────────────────────────────── */
.side {
  grid-area: side;
  background: var(--bg-side);
  color: var(--ink-on-side);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.side__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  background: var(--bg-side-acc);
}
.side__logo {
  width: 28px; height: 28px;
  background: var(--brand);
  border-radius: 6px;
  display: grid; place-items: center;
  font-weight: 700;
  color: var(--brand-text-on);
  font-size: 13px;
  flex-shrink: 0;
}
.side__logo img { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; }
.side__name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app.is-collapsed .side__name { display: none; }

.side__nav {
  padding: 12px 0;
  flex: 1;
}
.side__section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-on-side-mute);
  padding: 16px 22px 6px;
}
.app.is-collapsed .side__section-label { display: none; }

.side__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px;
  color: var(--ink-on-side);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s ease;
}
.side__item:hover {
  background: rgba(255, 255, 255, 0.05);
  text-decoration: none;
}
.side__item.is-active {
  background: rgba(255, 255, 255, 0.08);
  border-left-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.side__icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .9;
}
.app.is-collapsed .side__item { padding: 10px 0; justify-content: center; }
.app.is-collapsed .side__label { display: none; }

.side__footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--ink-on-side-mute);
}
.app.is-collapsed .side__footer { display: none; }

/* ─────────────────────────────────────────────
   Topbar
───────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  z-index: 5;
}
.topbar__menu {
  background: none;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: grid; place-items: center;
}
.topbar__menu:hover { background: var(--rule-soft); }
.topbar__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  flex: 1;
}
.topbar__title strong { color: var(--ink); }
.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar__icon {
  background: none;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink-soft);
  cursor: pointer;
}
.topbar__icon:hover { background: var(--rule-soft); }
.topbar__user {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  cursor: pointer;
}
.topbar__user:hover { background: var(--rule-soft); }
.topbar__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-text-on);
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 600;
}
.topbar__username {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.topbar__signout {
  background: none;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.topbar__signout:hover { background: var(--rule-soft); }

/* ─────────────────────────────────────────────
   Main area
───────────────────────────────────────────── */
.main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px;
}

.page-head {
  margin-bottom: 24px;
}
.page-head__crumbs {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.page-head__crumbs a { color: var(--ink-soft); }
.page-head h1 {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-head__sub {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0;
}
.page-head__actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Tab visibility */
.tab { display: none; }
.tab.is-active { display: block; }

/* ─────────────────────────────────────────────
   Cards
───────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.card__head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--rule-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.card__head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.card__head-meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-left: auto;
}
.card__head-actions {
  display: flex; gap: 8px;
}
.card__body {
  padding: 22px;
}
.card__hint {
  padding: 0 22px 18px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.card__hint code { font-size: 11px; }
.card__hint a { color: var(--brand); }

/* ─────────────────────────────────────────────
   Stat tiles
───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat--accent {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff;
  border: 0;
}
.stat--accent .stat__label,
.stat--accent .stat__sub { color: rgba(255, 255, 255, 0.78); }
.stat__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-mute);
}
.stat__value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 4px;
}
.stat__sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.stat__delta--up { color: var(--green); font-weight: 600; }
.stat__delta--down { color: var(--red); font-weight: 600; }

/* ─────────────────────────────────────────────
   Forms
───────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field select,
.field textarea,
input.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus,
input.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field__hint {
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 2px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  padding: 18px 22px;
}
.grid-form__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid var(--rule-soft);
  padding-top: 14px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--rule-soft); }
.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-text-on);
}
.btn--primary:hover { background: var(--brand-strong); }
.btn--danger {
  background: #fff;
  border-color: var(--red);
  color: var(--red);
}
.btn--danger:hover { background: #fef2f2; }
.btn--mini { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch__slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 22px;
  cursor: pointer;
  transition: background .15s ease;
}
.switch__slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.switch input:checked + .switch__slider { background: var(--brand); }
.switch input:checked + .switch__slider::before { transform: translateX(16px); }

/* ─────────────────────────────────────────────
   Tables
───────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-mute);
  background: var(--bg-elevated);
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule-soft);
  color: var(--ink);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-elevated); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.muted { color: var(--ink-mute); }
.table--clickable tbody tr { cursor: pointer; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--rule-soft);
  color: var(--ink-soft);
  letter-spacing: .02em;
}
.tag--green { background: rgba(16,185,129,.15); color: #047857; }
.tag--amber { background: rgba(245,158,11,.15); color: #92400e; }
.tag--red   { background: rgba(239,68,68,.15);  color: #b91c1c; }
.tag--blue  { background: rgba(37,99,235,.12);  color: #1e3a8a; }
.tag--purple{ background: rgba(139,92,246,.15); color: #5b21b6; }

/* ─────────────────────────────────────────────
   Misc
───────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 28px;
  color: var(--ink-soft);
  font-size: 13px;
}
.hint {
  padding: 10px 22px 18px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.hint code { font-size: 11px; }

.subs {
  list-style: none;
  margin: 0;
  padding: 0;
}
.subs li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--rule-soft);
}
.subs li:last-child { border-bottom: 0; }
.sub-card__main { flex: 1; min-width: 0; }
.sub-card__title { font-weight: 600; font-size: 13px; }
.sub-card__meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.sub-card__actions { display: flex; gap: 6px; }

.quick-row {
  display: grid;
  grid-template-columns: 22px 80px 1fr;
  align-items: center;
  padding: 6px 0;
  gap: 10px;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 13px;
  cursor: pointer;
}
.quick-row:last-child { border-bottom: 0; }
.quick-row:hover { background: var(--bg-elevated); }
.quick-row__id { font-family: 'SF Mono', Consolas, monospace; font-size: 11px; color: var(--ink-mute); }
.quick-row__name { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  border-top: 1px solid var(--rule-soft);
  font-size: 12px;
  color: var(--ink-soft);
}
.pg__nav { display: flex; gap: 6px; }
.pg__btn {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
.pg__btn:disabled { opacity: .4; cursor: not-allowed; }

.summary__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 24px;
  margin: 0;
  padding: 18px 22px;
}
.summary__grid > div { display: flex; flex-direction: column; gap: 2px; }
.summary__grid dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-mute);
  font-weight: 600;
}
.summary__grid dd {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

.brand-logo-row {
  display: flex; gap: 14px; align-items: center;
  padding: 18px 22px;
}
.brand-logo-row img {
  width: 64px; height: 64px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
}
.color-input {
  display: flex; gap: 10px; align-items: center;
}
.color-input input[type="color"] {
  width: 40px; height: 36px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

/* Login page — Telesis corporate split layout */
.login {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  background: var(--bg);
}
.login__hero {
  flex: 1.4;
  position: relative;
  background: linear-gradient(135deg, #0c2340 0%, #143761 60%, #1e4d8c 100%);
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.login__hero--image {
  background-size: cover;
  background-position: center;
}
.login__hero--image::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(12, 35, 64, 0.92) 0%, rgba(20, 55, 97, 0.88) 50%, rgba(30, 77, 140, 0.85) 100%);
  z-index: 0;
}
/* Decorative accent shape (orange swoop) */
.login__hero::after {
  content: '';
  position: absolute;
  right: -240px; top: -160px;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(224, 123, 31, 0.22) 0%, rgba(224, 123, 31, 0.10) 35%, transparent 65%);
  pointer-events: none;
  z-index: 1;
}
.login__hero > * { position: relative; z-index: 2; }

.login__brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.login__brand-logo {
  height: 56px;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  overflow: hidden;
}
.login__brand-logo img { height: 40px; max-width: 240px; object-fit: contain; }
.login__brand-logo span {
  font-weight: 700;
  color: #0c2340;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.login__hero-content {
  max-width: 560px;
}
.login__hero-tagline {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 14px;
  padding: 4px 10px;
  border: 1px solid rgba(224, 123, 31, 0.4);
  border-radius: 999px;
  background: rgba(224, 123, 31, 0.08);
}
.login__hero-content h1 {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.18;
  margin: 0 0 18px 0;
  letter-spacing: -0.02em;
}
.login__hero-content h1 .accent {
  color: var(--brand);
}
.login__hero-content p {
  font-size: 16px;
  line-height: 1.6;
  margin: 0 0 28px 0;
  color: rgba(255, 255, 255, 0.78);
}

.login__contact {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}
.login__contact a { color: rgba(255, 255, 255, 0.92); text-decoration: none; }
.login__contact a:hover { color: var(--brand); }
.login__contact-row {
  display: flex; align-items: center; gap: 10px;
}
.login__contact-row svg { width: 14px; height: 14px; opacity: 0.7; }

.login__hero-footer {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 24px;
}

.login__form-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 48px;
  background: #fff;
  min-width: 380px;
}
.login__form {
  width: 100%;
  max-width: 380px;
}
.login__form-logo {
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  min-height: 70px;
}
.login__form-logo img {
  max-height: 70px;
  max-width: 260px;
  object-fit: contain;
}
.login__form-logo span {
  font-size: 32px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.01em;
}
.login__form h2 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 6px 0;
  letter-spacing: -0.01em;
  color: #0c2340;
}
.login__form > p {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 28px 0;
}
.login__form .field { margin-bottom: 16px; }
.login__form .field > span {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.login__form input {
  padding: 12px 14px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: #fafbfc;
}
.login__form input:focus {
  background: #fff;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(224, 123, 31, 0.12);
}
.login__form .login__submit {
  width: 100%;
  margin-top: 12px;
  padding: 13px;
  background: var(--brand);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: background .12s ease, transform .12s ease;
  box-shadow: 0 4px 12px rgba(224, 123, 31, 0.25);
}
.login__submit:hover {
  background: #c66818;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(224, 123, 31, 0.35);
}
.login__alt {
  margin-top: 26px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  padding-top: 20px;
  border-top: 1px solid var(--rule-soft);
}
.login__alt a { color: var(--brand); font-weight: 600; }
.login__err {
  background: #fef2f2;
  border: 1px solid rgba(239,68,68,.25);
  color: var(--red);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-weight: 500;
}

@media (max-width: 980px) {
  .login { flex-direction: column; }
  .login__hero {
    flex: 0 0 auto;
    padding: 32px 28px 28px;
    min-height: 280px;
  }
  .login__hero-content h1 { font-size: 26px; }
  .login__hero-content p { font-size: 14px; }
  .login__form-wrap {
    flex: 1;
    padding: 32px 24px;
    min-width: 0;
  }
}

/* Chart containers */
.chart-wrap {
  position: relative;
  height: 340px;
  padding: 8px 4px;
}
.chart-wrap--tall { height: 380px; }

/* Responsive: mobile / narrow */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 0 1fr;
  }
  .app.is-open {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .side {
    transition: transform .2s ease;
  }
  .topbar__menu { display: grid; }
}
