:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --surface-3: #e7edf6;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.10);
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --brand-soft: #dbeafe;
  --success: #0f9f6e;
  --success-soft: #d9f7eb;
  --warning: #d97706;
  --warning-soft: #fff3d6;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 16px 40px rgba(15, 23, 42, .10);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #08111f;
    --surface: #0f1a2b;
    --surface-2: #162338;
    --surface-3: #1b2b44;
    --text: #f8fafc;
    --muted: #a3b0c2;
    --border: rgba(255,255,255,.10);
    --brand: #60a5fa;
    --brand-strong: #3b82f6;
    --brand-soft: rgba(59,130,246,.18);
    --success: #34d399;
    --success-soft: rgba(16,185,129,.16);
    --warning: #fbbf24;
    --warning-soft: rgba(245,158,11,.17);
    --danger: #fb7185;
    --danger-soft: rgba(244,63,94,.17);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.18), 0 1px 3px rgba(0,0,0,.28);
    --shadow-md: 0 18px 48px rgba(0,0,0,.32);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 10% -10%, rgba(37,99,235,.16), transparent 34%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(37,99,235,.28);
  outline-offset: 2px;
}

.app-shell { min-height: 100dvh; }

.login-page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  background: var(--bg);
}
.login-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(36px, 6vw, 88px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(145deg, rgba(8,17,31,.92), rgba(17,38,73,.88)),
    radial-gradient(circle at 70% 20%, #2563eb 0, transparent 32%);
  color: white;
}
.login-hero::after {
  content: "";
  position: absolute;
  inset: auto -8% -20% auto;
  width: min(46vw, 580px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(96,165,250,.34), transparent 66%);
  filter: blur(10px);
}
.brand-lockup { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(14px);
  font-weight: 800; letter-spacing: -.04em;
}
.brand-text strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand-text span { font-size: 12px; color: rgba(255,255,255,.68); }
.hero-copy { max-width: 700px; position: relative; z-index: 1; }
.hero-kicker { margin: 0 0 14px; text-transform: uppercase; letter-spacing: .15em; font-size: 12px; font-weight: 800; color: #93c5fd; }
.hero-copy h1 { margin: 0; font-size: clamp(42px, 6vw, 78px); line-height: .98; letter-spacing: -.055em; max-width: 780px; }
.hero-copy p { margin: 24px 0 0; color: rgba(255,255,255,.72); max-width: 620px; font-size: clamp(16px, 1.6vw, 20px); line-height: 1.65; }
.hero-points { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.hero-pill { padding: 10px 13px; border-radius: 999px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); font-size: 13px; color: rgba(255,255,255,.84); }
.login-panel {
  padding: calc(34px + var(--safe-top)) clamp(24px, 5vw, 72px) calc(34px + var(--safe-bottom));
  display: flex; flex-direction: column; justify-content: center;
}
.login-card { width: min(100%, 470px); margin: 0 auto; }
.login-card h2 { margin: 0; font-size: clamp(30px, 4vw, 42px); letter-spacing: -.04em; }
.login-card > p { margin: 10px 0 30px; color: var(--muted); line-height: 1.55; }
.field { display: grid; gap: 8px; margin: 0 0 17px; }
.field label { font-size: 13px; font-weight: 720; color: var(--muted); }
.input-wrap { position: relative; }
.input {
  width: 100%; min-height: 54px; padding: 0 16px; border: 1px solid var(--border); border-radius: 15px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); transition: border-color .16s ease, box-shadow .16s ease;
}
.input:hover { border-color: rgba(37,99,235,.35); }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(37,99,235,.10); outline: none; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); min-width: 44px; min-height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; }
.primary-btn, .secondary-btn, .danger-btn, .ghost-btn {
  min-height: var(--tap); border-radius: 15px; padding: 0 18px; border: 0; font-weight: 760; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; transition: transform .14s ease, filter .14s ease, background .14s ease;
}
.primary-btn { width: 100%; min-height: 56px; background: var(--brand); color: white; box-shadow: 0 10px 24px rgba(37,99,235,.22); }
.primary-btn:hover { filter: brightness(1.03); }
.primary-btn:active, .secondary-btn:active, .danger-btn:active, .ghost-btn:active { transform: scale(.985); }
.secondary-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.danger-btn { background: var(--danger-soft); color: var(--danger); }
.ghost-btn { background: transparent; color: var(--muted); }
.demo-box { margin-top: 20px; padding: 15px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-size: 13px; line-height: 1.55; }
.demo-box strong { color: var(--text); }
.login-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; font-weight: 700; }

.dashboard-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; padding: 22px 18px; background: rgba(255,255,255,.82);
  border-right: 1px solid var(--border); backdrop-filter: blur(18px); display: flex; flex-direction: column; z-index: 30;
}
@media (prefers-color-scheme: dark) { .sidebar { background: rgba(15,26,43,.86); } }
.sidebar .brand-lockup { color: var(--text); }
.sidebar .brand-mark { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.sidebar .brand-text span { color: var(--muted); }
.nav-list { display: grid; gap: 6px; margin-top: 30px; }
.nav-btn {
  min-height: 48px; display: flex; align-items: center; gap: 13px; padding: 0 14px; border: 0; border-radius: 14px;
  background: transparent; color: var(--muted); font-weight: 720; cursor: pointer; text-align: left;
}
.nav-btn svg { width: 21px; height: 21px; flex: none; }
.nav-btn.active { background: var(--brand-soft); color: var(--brand); }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.sidebar-bottom { margin-top: auto; display: grid; gap: 10px; }
.profile-card { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--border); }
.avatar { width: 42px; height: 42px; border-radius: 14px; background: linear-gradient(145deg, #2563eb, #7c3aed); color: white; display: grid; place-items: center; font-weight: 800; }
.profile-card strong { display: block; font-size: 13px; }
.profile-card span { font-size: 12px; color: var(--muted); }
.main-area { min-width: 0; padding: 0 0 92px; }
.topbar {
  position: sticky; top: 0; z-index: 20; min-height: 76px; padding: calc(12px + var(--safe-top)) clamp(18px, 3vw, 36px) 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  background: color-mix(in srgb, var(--bg) 84%, transparent); backdrop-filter: blur(18px); border-bottom: 1px solid var(--border);
}
.topbar-title small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.topbar-title h1 { margin: 0; font-size: clamp(22px, 3vw, 32px); letter-spacing: -.035em; }
.topbar-actions { display: flex; gap: 10px; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-sm);
}
.icon-btn svg { width: 21px; height: 21px; }
.content { padding: clamp(18px, 3vw, 36px); max-width: 1540px; margin: 0 auto; }

.welcome-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; padding: clamp(20px, 3vw, 32px);
  border-radius: var(--radius-lg); color: white; background:
  radial-gradient(circle at 92% 25%, rgba(147,197,253,.28), transparent 28%),
  linear-gradient(130deg, #0f2a55, #1d4ed8 58%, #1e40af);
  box-shadow: var(--shadow-md); overflow: hidden; position: relative;
}
.welcome-strip h2 { margin: 0; font-size: clamp(26px, 4vw, 40px); letter-spacing: -.04em; }
.welcome-strip p { margin: 9px 0 0; color: rgba(255,255,255,.75); max-width: 720px; line-height: 1.55; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px; border-radius: 999px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.14); white-space: nowrap; font-size: 13px; font-weight: 760; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 6px rgba(52,211,153,.14); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi-card, .panel { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.kpi-card { border-radius: var(--radius-md); padding: 18px; min-width: 0; }
.kpi-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 760; text-transform: uppercase; letter-spacing: .06em; }
.kpi-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand); }
.kpi-icon svg { width: 20px; height: 20px; }
.kpi-value { margin: 18px 0 4px; font-size: clamp(28px, 4vw, 38px); font-weight: 820; letter-spacing: -.045em; }
.kpi-meta { color: var(--muted); font-size: 12px; }
.kpi-meta b { color: var(--success); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, .85fr); gap: 16px; margin-top: 16px; }
.panel { border-radius: var(--radius-md); padding: 18px; min-width: 0; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel-title h3 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.panel-title p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented button { min-height: 36px; border: 0; border-radius: 9px; padding: 0 12px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.chart-wrap { min-height: 280px; width: 100%; overflow: hidden; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.legend-dot.blue { background: #3b82f6; }.legend-dot.green { background: #10b981; }.legend-dot.orange { background: #f59e0b; }

.machine-list { display: grid; gap: 10px; }
.machine-row { display: grid; grid-template-columns: 46px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 12px; border-radius: 15px; background: var(--surface-2); border: 1px solid transparent; }
.machine-row:hover { border-color: var(--border); }
.machine-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 18px; font-weight: 820; background: var(--surface); border: 1px solid var(--border); }
.machine-row strong { display: block; font-size: 14px; }
.machine-row span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.state-badge { padding: 8px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.state-running { color: var(--success); background: var(--success-soft); }
.state-idle { color: var(--warning); background: var(--warning-soft); }
.state-down { color: var(--danger); background: var(--danger-soft); }

.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin: 16px 0; }
.quick-action { min-height: 116px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); padding: 17px; text-align: left; cursor: pointer; box-shadow: var(--shadow-sm); }
.quick-action:hover { border-color: rgba(37,99,235,.28); transform: translateY(-1px); }
.quick-action svg { width: 24px; height: 24px; color: var(--brand); }
.quick-action strong { display: block; margin-top: 18px; font-size: 14px; }
.quick-action span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.operator-card { border-radius: var(--radius-lg); padding: clamp(20px, 4vw, 32px); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.machine-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.machine-hero h2 { margin: 0; font-size: clamp(30px, 7vw, 48px); letter-spacing: -.05em; }
.machine-hero p { margin: 7px 0 0; color: var(--muted); }
.progress-card { margin-top: 22px; padding: 16px; border-radius: 18px; background: var(--surface-2); }
.progress-head { display: flex; justify-content: space-between; gap: 14px; font-size: 13px; }
.progress-track { height: 12px; border-radius: 999px; background: var(--surface-3); margin-top: 12px; overflow: hidden; }
.progress-fill { width: 68%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #2563eb, #60a5fa); }
.operator-actions { display: grid; grid-template-columns: 1.25fr .75fr .75fr; gap: 12px; margin-top: 18px; }
.operator-actions button { min-height: 66px; }
.big-action { min-height: 78px !important; font-size: 16px; }

.data-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.search-box { position: relative; flex: 1 1 280px; }
.search-box input { width: 100%; min-height: 48px; padding: 0 16px 0 46px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.search-box svg { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); }
.toolbar-buttons { display: flex; gap: 8px; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { min-height: 36px; display: inline-flex; align-items: center; gap: 8px; padding: 0 11px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); border: 0; font-size: 12px; font-weight: 760; }
.table-wrap { overflow: auto; border-radius: 16px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 900px; background: var(--surface); }
th, td { padding: 14px 15px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; z-index: 1; }
tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 42%, transparent); }
.row-actions { display: flex; gap: 6px; }
.row-actions button { min-width: 40px; min-height: 40px; border: 0; border-radius: 11px; background: var(--surface-2); color: var(--text); cursor: pointer; }

.bottom-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; padding: 8px 10px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent); border-top: 1px solid var(--border); backdrop-filter: blur(20px);
}
.bottom-nav-inner { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; max-width: 660px; margin: 0 auto; }
.bottom-nav button { min-height: 54px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 2px; font-size: 10px; font-weight: 730; cursor: pointer; }
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--brand); background: var(--brand-soft); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(2,6,23,.55); backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.sheet { width: min(100%, 680px); max-height: 88dvh; overflow: auto; border-radius: 26px 26px 18px 18px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); padding: 12px 18px calc(18px + var(--safe-bottom)); animation: sheetUp .2s ease; }
.sheet-handle { width: 44px; height: 5px; border-radius: 999px; background: var(--surface-3); margin: 0 auto 14px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.sheet-header h3 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.sheet-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin-top: 18px; }
.sheet-footer { position: sticky; bottom: -1px; display: grid; grid-template-columns: .8fr 1.2fr; gap: 10px; padding-top: 16px; background: linear-gradient(transparent, var(--surface) 24%); }
@keyframes sheetUp { from { transform: translateY(30px); opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom)); transform: translateX(-50%); z-index: 120; min-width: min(90vw, 360px); padding: 13px 15px; border-radius: 14px; background: #111827; color: white; box-shadow: var(--shadow-md); text-align: center; font-size: 13px; font-weight: 700; animation: toastIn .18s ease; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .dashboard-shell { grid-template-columns: 230px minmax(0,1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .quick-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 820px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-panel { min-height: 100dvh; justify-content: flex-start; padding-top: calc(56px + var(--safe-top)); }
  .dashboard-shell { display: block; }
  .sidebar { display: none; }
  .main-area { padding-bottom: 92px; }
  .bottom-nav { display: block; }
  .topbar { min-height: 66px; padding-left: 16px; padding-right: 16px; }
  .content { padding: 16px; }
  .welcome-strip { align-items: flex-start; flex-direction: column; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .operator-actions { grid-template-columns: 1fr 1fr; }
  .operator-actions .big-action { grid-column: 1 / -1; }
  .table-wrap { border: 0; overflow: visible; }
  table { min-width: 0; border: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; padding: 15px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
  td { padding: 0; border: 0; display: grid; gap: 3px; }
  td::before { content: attr(data-label); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 760; }
  td:last-child { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  :root { --radius-lg: 22px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 15px; }
  .kpi-value { font-size: 28px; }
  .quick-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .quick-action { min-height: 104px; padding: 15px; }
  .machine-hero { flex-direction: column; }
  .sheet-grid { grid-template-columns: 1fr; }
  .toolbar-buttons { width: 100%; }
  .toolbar-buttons button { flex: 1; }
  .topbar-title small { display: none; }
}

@media (max-width: 390px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
  tbody tr { grid-template-columns: 1fr; }
  td:last-child { grid-column: auto; }
}

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