/* ── Payline — Master / Operator design system ────────────────────
 *
 * Apple Enterprise aesthetic:
 *   • Light background, dense whitespace, subtle dividers
 *   • SF Pro typography, clear hierarchy
 *   • Payline teal as the only brand accent
 *   • Status carried by color dots, never buried in numbers
 *   • Tappable everywhere — no tiny text, no dense tables
 *
 * "So easy a 3-year-old can use it":
 *   • Big tiles, not data grids
 *   • Plain-English ("Need a look" not "Alerts queue")
 *   • One main action per screen, drill in on tap
 *   • Numbers shown in human formats ($1.2K not 124000)
 *   • Color tells the story — green / amber / red dots
 * ─────────────────────────────────────────────────────────────── */

:root {
  /* ── Color: Apple Light System ── */
  --bg:           #F5F5F7;        /* Apple light gray */
  --surface:      #FFFFFF;
  --surface-2:    #FAFAFA;
  --border:       rgba(0, 0, 0, 0.08);
  --border-strong:rgba(0, 0, 0, 0.16);
  --divider:      rgba(0, 0, 0, 0.06);

  --text:         #1D1D1F;        /* Apple near-black */
  --text-2:       #424245;
  --text-3:       #6E6E73;
  --text-4:       #8E8E93;

  --teal:         #00B87A;        /* Payline teal, slightly darkened for light bg */
  --teal-2:       #00A06A;
  --teal-bg:      rgba(0, 184, 122, 0.10);
  --teal-border:  rgba(0, 184, 122, 0.30);

  --green:        #34C759;
  --green-bg:     rgba(52, 199, 89, 0.12);
  --amber:        #FF9F0A;
  --amber-bg:     rgba(255, 159, 10, 0.12);
  --red:          #FF3B30;
  --red-bg:       rgba(255, 59, 48, 0.10);
  --blue:         #0071E3;        /* Apple blue */
  --blue-bg:      rgba(0, 113, 227, 0.10);

  /* ── Typography ── */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
          'Inter', system-ui, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', Menlo, Monaco, monospace;

  --fs-tiny:     11px;
  --fs-small:    13px;
  --fs-body:     15px;
  --fs-h4:       17px;
  --fs-h3:       22px;
  --fs-h2:       28px;
  --fs-h1:       36px;
  --fs-display:  56px;

  /* ── Spacing ── */
  --gap-xs:  4px;
  --gap-sm:  8px;
  --gap:     16px;
  --gap-md:  24px;
  --gap-lg:  32px;
  --gap-xl:  48px;

  /* ── Touch ── */
  --touch-min: 48px;
  --touch-cta: 56px;

  /* ── Radius ── */
  --r-sm: 8px;
  --r:    12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;

  /* ── Shadows: subtle, Apple-grade ── */
  --shadow-card:    0 1px 3px rgba(0, 0, 0, 0.05),
                    0 1px 0 rgba(0, 0, 0, 0.02) inset;
  --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.08),
                       0 1px 0 rgba(0, 0, 0, 0.02) inset;
  --shadow-overlay: 0 24px 60px rgba(0, 0, 0, 0.16),
                    0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-body); line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--blue); text-decoration: none; }
img, svg { display: block; max-width: 100%; }

/* ── App shell ──────────────────────────────────────────────── */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap) var(--gap-lg);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar .brand { display: flex; align-items: center; gap: var(--gap-sm); }
.topbar .logo { font-size: var(--fs-h3); font-weight: 700; letter-spacing: -0.5px; }
.topbar .logo .dot { color: var(--teal); }
.topbar .crumb { font-size: var(--fs-small); color: var(--text-3); padding-left: var(--gap-sm); border-left: 1px solid var(--border); margin-left: var(--gap-sm); }

.topbar-actions { display: flex; align-items: center; gap: var(--gap-sm); }

/* Top tab navigation between master pages */
.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-left: var(--gap);
}
.topnav a {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.2px;
  transition: background 120ms ease, color 120ms ease;
}
.topnav a:hover { color: var(--text); }
.topnav a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.user-pill {
  display: inline-flex; align-items: center; gap: var(--gap-sm);
  padding: 6px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 100px; font-size: var(--fs-small); font-weight: 500; color: var(--text-2);
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  display: flex; align-items: center; justify-content: center;
  color: #FFF; font-weight: 700; font-size: 12px;
}

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-3);
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.main { padding: var(--gap-lg); max-width: 1400px; margin: 0 auto; width: 100%; }
.page-title { font-size: var(--fs-h1); font-weight: 700; letter-spacing: -1px; margin-bottom: var(--gap-sm); }
.page-sub   { font-size: var(--fs-h4); color: var(--text-3); margin-bottom: var(--gap-lg); }

/* ── Hero KPI tiles (top of dashboard) ─────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  margin-bottom: var(--gap-lg);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-md);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
  box-shadow: var(--shadow-card);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-card-hover); border-color: var(--border-strong); }
.kpi:active { transform: scale(0.98); }
.kpi .label { font-size: var(--fs-small); color: var(--text-3); font-weight: 500; letter-spacing: 0.2px; margin-bottom: var(--gap-sm); display: flex; align-items: center; gap: var(--gap-xs); }
.kpi .label svg { width: 14px; height: 14px; }
.kpi .value { font-size: var(--fs-h1); font-weight: 700; letter-spacing: -1px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.kpi .value.green { color: var(--green); }
.kpi .value.red   { color: var(--red); }
.kpi .delta { font-size: var(--fs-small); color: var(--text-3); margin-top: 4px; font-weight: 500; }
.kpi .delta.up   { color: var(--green); }
.kpi .delta.down { color: var(--red); }

/* ── Section + cards ─────────────────────────────────────── */
.section { margin-bottom: var(--gap-xl); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--gap); }
.section-title { font-size: var(--fs-h3); font-weight: 600; letter-spacing: -0.3px; }
.section-link  { font-size: var(--fs-small); color: var(--blue); font-weight: 500; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
}
.card-row {
  display: flex; align-items: center; padding: var(--gap-md);
  gap: var(--gap-md);
  border-bottom: 1px solid var(--divider);
  transition: background 100ms ease;
}
.card-row:last-child { border-bottom: none; }
.card-row:hover { background: var(--surface-2); cursor: pointer; }

/* ── Status dots ──────────────────────────────────────────── */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.green  { background: var(--green); }
.dot.amber  { background: var(--amber); }
.dot.red    { background: var(--red); }
.dot.blue   { background: var(--blue); }
.dot.gray   { background: var(--text-4); }
.dot.pulse  { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Recommendation cards (the magic) ───────────────────── */
.recs { display: grid; gap: var(--gap-sm); }
.rec {
  display: flex; align-items: flex-start; gap: var(--gap-md);
  padding: var(--gap-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-4);
  border-radius: var(--r-md);
  transition: transform 150ms ease, box-shadow 150ms ease;
  cursor: pointer;
}
.rec:hover { transform: translateY(-1px); box-shadow: var(--shadow-card-hover); }
.rec.critical { border-left-color: var(--red);   background: linear-gradient(90deg, var(--red-bg), var(--surface) 30%); }
.rec.high     { border-left-color: var(--amber); background: linear-gradient(90deg, var(--amber-bg), var(--surface) 30%); }
.rec.medium   { border-left-color: var(--blue);  }
.rec.low      { border-left-color: var(--text-4); }

.rec-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--teal-bg); color: var(--teal);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.rec.critical .rec-icon { background: var(--red-bg);   color: var(--red); }
.rec.high     .rec-icon { background: var(--amber-bg); color: var(--amber); }
.rec.low      .rec-icon { background: var(--surface-2); color: var(--text-3); }
.rec-icon svg { width: 22px; height: 22px; }

.rec-body { flex: 1; min-width: 0; }
.rec-title { font-size: var(--fs-h4); font-weight: 600; color: var(--text); margin-bottom: 4px; }
.rec-detail { font-size: var(--fs-small); color: var(--text-3); }
.rec-meta { display: flex; gap: var(--gap-md); margin-top: var(--gap-sm); font-size: var(--fs-tiny); color: var(--text-4); }
.rec-impact { font-weight: 600; color: var(--green); }

.rec-action {
  padding: var(--gap-xs) var(--gap); height: 36px;
  background: var(--text); color: #FFF;
  border-radius: 100px; font-size: var(--fs-small); font-weight: 600;
  align-self: center; flex-shrink: 0;
  transition: opacity 100ms ease;
}
.rec-action:hover { opacity: 0.85; }
.rec-action:active { opacity: 0.65; }

/* ── Location cards ─────────────────────────────────────── */
.loc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--gap); }
.loc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-md);
  transition: transform 150ms ease, box-shadow 150ms ease;
  cursor: pointer;
}
.loc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card-hover); }
.loc-card .loc-name { font-size: var(--fs-h4); font-weight: 600; margin-bottom: 2px; }
.loc-card .loc-city { font-size: var(--fs-small); color: var(--text-3); margin-bottom: var(--gap); }
.loc-card .loc-stats { display: flex; justify-content: space-between; font-size: var(--fs-small); }
.loc-card .stat .l { display: block; color: var(--text-3); font-size: var(--fs-tiny); margin-bottom: 2px; }
.loc-card .stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.loc-card .loc-bar { height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: var(--gap); overflow: hidden; }
.loc-card .loc-bar-fill { height: 100%; background: var(--teal); transition: width 300ms ease; }

/* ── Machine grid ────────────────────────────────────────── */
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap-sm); }
.machine-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--gap);
  cursor: pointer;
  transition: border-color 100ms ease, transform 100ms ease;
}
.machine-tile:hover { border-color: var(--teal); transform: translateY(-1px); }
.machine-tile .machine-id { font-family: var(--font-mono); font-size: var(--fs-tiny); color: var(--text-3); }
.machine-tile .title { font-size: var(--fs-h4); font-weight: 600; margin: 4px 0; }
.machine-tile .row { display: flex; justify-content: space-between; align-items: center; font-size: var(--fs-small); margin-top: var(--gap-sm); }
.machine-tile .row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.machine-tile.playing { border-color: var(--green); }
.machine-tile.alerted { border-color: var(--red); background: linear-gradient(0deg, var(--red-bg) 0%, var(--surface) 30%); }

/* ── Tables (used sparingly) ─────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: var(--gap-sm) var(--gap-md); font-size: var(--fs-tiny); font-weight: 600; color: var(--text-3); letter-spacing: 0.5px; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.table td { padding: var(--gap) var(--gap-md); font-size: var(--fs-small); border-bottom: 1px solid var(--divider); }
.table tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--gap-sm);
  min-height: var(--touch-min); padding: 0 var(--gap-md);
  border-radius: 100px;
  font-size: var(--fs-small); font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 120ms ease, transform 80ms ease;
}
.btn:hover { background: var(--surface); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--text); color: #FFF; border-color: var(--text); }
.btn.primary:hover { opacity: 0.85; }
.btn.teal { background: var(--teal); color: #FFF; border-color: var(--teal); }
.btn.danger { background: var(--red); color: #FFF; border-color: var(--red); }

.empty {
  text-align: center; padding: var(--gap-xl) var(--gap-md);
  color: var(--text-3);
}
.empty svg { width: 56px; height: 56px; margin-bottom: var(--gap); color: var(--text-4); }
.empty .h { font-size: var(--fs-h4); font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* ── Drawer ───────────────────────────────────────────────── */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity 250ms ease; z-index: 200; }
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 540px;
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 201; overflow-y: auto;
  box-shadow: var(--shadow-overlay);
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: var(--gap-md); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.drawer-body { padding: var(--gap-md); }
.drawer-actions { padding: var(--gap-md); border-top: 1px solid var(--border); display: flex; gap: var(--gap-sm); position: sticky; bottom: 0; background: var(--surface); }
.drawer-actions .btn { flex: 1; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .drawer { width: 100%; }
}
@media (max-width: 600px) {
  .kpi-row { grid-template-columns: 1fr; }
  .main { padding: var(--gap); }
}
