:root {
      color-scheme: light;
      --bg: #f4f6f8;
      --panel: #ffffff;
      --panel-soft: #eef3f6;
      --text: #1d252c;
      --muted: #687580;
      --line: #d8e0e6;
      --primary: #176b87;
      --primary-dark: #105369;
      --accent: #c17922;
      --good: #1e7f4f;
      --bad: #b83a3a;
      --shadow: 0 14px 34px rgba(29, 37, 44, 0.09);
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      font-family: Arial, "Noto Sans Armenian", sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    button, input, select, textarea {
      font: inherit;
    }

    button {
      border: 0;
      border-radius: 6px;
      background: var(--primary);
      color: #fff;
      padding: 10px 14px;
      cursor: pointer;
      min-height: 40px;
    }

    button:hover { background: var(--primary-dark); }
    button.secondary { background: #e4ebef; color: var(--text); }
    button.secondary:hover { background: #d3dee5; }
    button.danger { background: var(--bad); }
    button:disabled { opacity: 0.48; cursor: not-allowed; }
    button.icon { width: 40px; padding: 0; display: inline-grid; place-items: center; }

    input, select, textarea {
      width: 100%;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: #fff;
      color: var(--text);
      padding: 10px 11px;
      min-height: 40px;
      box-sizing: border-box;
    }

    textarea { min-height: 90px; resize: vertical; }

    label {
      display: grid;
      gap: 6px;
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
    }

    .app-shell {
      min-height: 100vh;
      display: grid;
      grid-template-columns: 260px 1fr;
    }

    aside {
      background: #23313a;
      color: #fff;
      padding: 22px 18px;
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    .brand {
      display: grid;
      gap: 7px;
      padding-bottom: 14px;
      border-bottom: 1px solid rgba(255,255,255,0.14);
    }

    .brand-title {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .brand-logo {
      width: 42px;
      height: 42px;
      object-fit: contain;
      border-radius: 8px;
      background: #fff;
      padding: 3px;
      flex: 0 0 auto;
    }

    .brand strong { font-size: 19px; letter-spacing: 0; }
    .brand span { color: #b8c7d0; font-size: 13px; }
    .brand .app-version { color: #8fa5b1; font-size: 12px; }

    .brand-install {
      width: 100%;
      margin-top: 4px;
      justify-content: center;
      color: #08212c;
      background: #ffffff;
      border-color: rgba(255,255,255,0.7);
    }

    .install-hidden {
      display: none !important;
    }

    nav {
      display: grid;
      gap: 8px;
    }

    .nav-btn {
      width: 100%;
      text-align: left;
      background: transparent;
      color: #d9e4ea;
      border: 1px solid transparent;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .nav-btn:hover, .nav-btn.active {
      background: rgba(255,255,255,0.09);
      border-color: rgba(255,255,255,0.14);
    }

    main {
      min-width: 0;
      padding: 26px;
    }

    .topbar {
      display: flex;
      justify-content: space-between;
      gap: 16px;
      align-items: flex-start;
      margin-bottom: 18px;
    }

    h1, h2, h3 { margin: 0; letter-spacing: 0; }
    h1 { font-size: 28px; }
    h2 { font-size: 19px; }
    h3 { font-size: 15px; }
    p { color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

    .page { display: none; }
    .page.active { display: grid; gap: 16px; }

    .toolbar {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      align-items: end;
    }

    .panel {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: var(--shadow);
      padding: 16px;
    }

    .grid {
      display: grid;
      gap: 12px;
    }

    .cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

    .entry-race-picker {
      display: grid;
      gap: 8px;
    }

    .entry-race-tools {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 8px;
    }

    .stats {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 12px;
    }

    .stat {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 14px;
    }

    .stat span { color: var(--muted); font-size: 13px; }
    .stat strong { display: block; font-size: 27px; margin-top: 5px; }

    table {
      width: 100%;
      border-collapse: collapse;
      background: #fff;
    }

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

    th {
      color: var(--muted);
      font-size: 12px;
      text-transform: uppercase;
      letter-spacing: 0;
      background: #f8fafb;
    }

    tr:hover td { background: #fbfcfd; }
    td.actions { width: 190px; white-space: nowrap; }

    td input:not([type="checkbox"]),
    td select {
      min-width: 86px;
      color: var(--text);
      background: #fff;
    }

    td input[data-time-trial],
    td input[data-time-trial-split] {
      font-variant-numeric: tabular-nums;
    }

    .table-wrap {
      overflow-x: auto;
      border: 1px solid var(--line);
      border-radius: 8px;
    }

    #timeTrialEditor table {
      min-width: 1180px;
    }

    #timeTrialEditor th,
    #timeTrialEditor td {
      white-space: nowrap;
    }

    #timeTrialEditor td:nth-child(3) {
      white-space: normal;
      min-width: 160px;
    }

    .time-split-input {
      width: 96px;
      min-width: 96px;
      text-align: center;
      font-weight: 700;
      color: var(--text);
      background: #fff;
      padding-left: 6px;
      padding-right: 6px;
    }

    .member-list {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.35;
      margin-top: 3px;
    }

    .badge {
      display: inline-flex;
      align-items: center;
      min-height: 24px;
      padding: 3px 8px;
      border-radius: 999px;
      background: var(--panel-soft);
      color: var(--text);
      font-size: 12px;
      font-weight: 700;
    }

    .badge.good { background: #dff2e8; color: var(--good); }
    .badge.bad { background: #f6dddd; color: var(--bad); }
    .badge.warn { background: #faefd8; color: #87520b; }

    .checkline {
      display: inline-flex;
      gap: 8px;
      align-items: center;
      width: auto;
      min-height: 40px;
    }

    .checkline input { width: auto; }

    .sync-status {
      min-height: 24px;
      color: var(--muted);
      font-weight: 700;
      align-self: center;
    }

    .sync-status.good { color: var(--good); }
    .sync-status.bad { color: var(--bad); }
    .sync-status.warn { color: #87520b; }

    .split {
      display: grid;
      grid-template-columns: 360px 1fr;
      gap: 16px;
      align-items: start;
    }

    .entry-list {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 8px;
      max-height: 330px;
      overflow: auto;
      padding: 2px;
    }

    .check-row {
      display: flex;
      gap: 8px;
      align-items: center;
      padding: 9px;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: #fff;
    }

    .entry-tools {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px;
      margin-top: 12px;
    }

    .entry-summary {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      align-items: center;
      margin-top: 12px;
      color: var(--muted);
      font-size: 13px;
    }

    .start-preview {
      margin-top: 14px;
      display: grid;
      gap: 8px;
      max-height: 250px;
      overflow: auto;
    }

    .start-item {
      display: grid;
      grid-template-columns: 54px 72px 1fr;
      gap: 8px;
      align-items: center;
      padding: 9px;
      border: 1px solid var(--line);
      border-radius: 6px;
      background: #fff;
      font-size: 13px;
    }

    .check-row input { width: 16px; min-height: 16px; }
    .check-row span { font-size: 13px; }

    .check-row .entry-team-name {
      width: 140px;
      min-height: 34px;
      margin-left: auto;
      font-size: 13px;
    }

    .race-workspace {
      display: grid;
      grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
      gap: 16px;
      align-items: start;
    }

    .sprint-grid {
      display: grid;
      gap: 10px;
    }

    .sprint-row {
      display: grid;
      grid-template-columns: 70px repeat(4, minmax(90px, 1fr));
      gap: 8px;
      align-items: center;
    }

    .muted { color: var(--muted); }
    .right { text-align: right; }
    .hidden { display: none !important; }

    body.live-focus {
      background: #101820;
    }

    body.live-focus aside,
    body.live-focus .topbar {
      display: none;
    }

    body.live-focus .app-shell {
      display: block;
    }

    body.live-focus main {
      padding: 0;
    }

    .live-screen {
      min-height: 100vh;
      background: #101820;
      color: #f7fbfd;
      padding: 28px;
      display: grid;
      grid-template-rows: auto auto 1fr;
      gap: 20px;
    }

    .live-header {
      display: flex;
      justify-content: space-between;
      align-items: end;
      gap: 18px;
      border-bottom: 1px solid rgba(255,255,255,0.16);
      padding-bottom: 18px;
    }

    .live-header h2 {
      font-size: 38px;
      line-height: 1.08;
    }

    .live-header p {
      color: #a9bdc8;
      margin-top: 7px;
    }

    .live-clock {
      font-size: 22px;
      color: #d9e8ef;
      text-align: right;
      white-space: nowrap;
    }

    .live-controls {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      align-items: end;
    }

    .live-controls label {
      color: #c7d6de;
      min-width: 300px;
    }

    .live-controls input,
    .live-controls select {
      background: #17252e;
      color: #fff;
      border-color: rgba(255,255,255,0.18);
    }

    .podium {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 14px;
    }

    .podium-card {
      background: #17252e;
      border: 1px solid rgba(255,255,255,0.14);
      border-radius: 8px;
      padding: 18px;
      min-height: 150px;
    }

    .podium-card:first-child {
      background: #f5f7f8;
      color: #101820;
    }

    .podium-rank {
      font-size: 42px;
      font-weight: 800;
      color: var(--accent);
    }

    .podium-bib {
      display: inline-flex;
      margin: 8px 0;
      padding: 4px 10px;
      border-radius: 6px;
      background: var(--accent);
      color: #fff;
      font-size: 22px;
      font-weight: 800;
    }

    .podium-name {
      font-size: 25px;
      font-weight: 800;
      line-height: 1.15;
    }

    .podium-team {
      color: #a9bdc8;
      margin-top: 5px;
    }

    .podium-card:first-child .podium-team {
      color: #50616b;
    }

    .live-table {
      overflow: hidden;
      border: 1px solid rgba(255,255,255,0.14);
      border-radius: 8px;
      background: #15222a;
    }

    .live-table table {
      background: transparent;
      color: #f7fbfd;
    }

    .live-table th {
      background: #21323d;
      color: #b9ccd6;
      font-size: 13px;
    }

    .live-table td {
      border-bottom-color: rgba(255,255,255,0.1);
      font-size: 20px;
      padding: 13px 12px;
    }

    .live-table tr:hover td {
      background: transparent;
    }

    .live-rank {
      width: 70px;
      color: var(--accent);
      font-size: 24px;
      font-weight: 800;
    }

    .live-points {
      font-size: 24px;
      font-weight: 800;
      text-align: right;
    }

    .current-out-screen {
      min-height: 58vh;
      display: grid;
      place-items: center;
      border: 1px solid rgba(255,255,255,0.14);
      border-radius: 8px;
      background: #030506;
      padding: 30px;
    }

    .current-out-number {
      font-size: clamp(120px, 25vw, 360px);
      line-height: 0.9;
      font-weight: 900;
      color: #fff;
      letter-spacing: 0;
      text-align: center;
    }

    .current-out-name {
      margin-top: 18px;
      color: #c9d5db;
      font-size: clamp(22px, 3vw, 44px);
      font-weight: 800;
      text-align: center;
    }

    .official-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 18px;
      margin-bottom: 18px;
      padding-bottom: 14px;
      border-bottom: 2px solid #1d252c;
    }

    .official-logo {
      width: 96px;
      height: 76px;
      object-fit: contain;
      flex: 0 0 auto;
    }

    .official-logo.uci {
      width: 150px;
    }

    .official-logo.yerevan {
      width: 86px;
    }

    .official-logo.uci {
      background: #101820;
      padding: 8px;
      border-radius: 4px;
    }

    .official-title {
      text-align: center;
      min-width: 0;
      flex: 1;
    }

    .official-title h1 {
      font-size: 21px;
      line-height: 1.2;
      text-transform: uppercase;
    }

    .official-title p {
      color: var(--text);
      margin-top: 5px;
      font-size: 13px;
    }

    .logo-tools {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      margin-top: 12px;
      padding: 10px 0;
      border-top: 1px solid var(--border);
    }

    .logo-tools span {
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
    }

    .result-view.active {
      background: var(--primary);
      color: #fff;
    }

    .result-category-tools {
      margin-top: 12px;
      display: grid;
      grid-template-columns: minmax(220px, 320px) 1fr;
      gap: 10px;
      align-items: end;
    }

    .category-buttons {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      align-items: center;
    }

    .category-chip.active {
      background: var(--primary);
      color: #fff;
    }

    .official-signatures {
      display: grid;
      grid-template-columns: repeat(2, minmax(220px, 1fr));
      gap: 48px;
      margin-top: 44px;
      page-break-inside: avoid;
    }

    .signature-block {
      display: grid;
      gap: 9px;
      color: var(--text);
      font-weight: 700;
    }

    .signature-line {
      border-bottom: 1.5px solid #1d252c;
      height: 34px;
    }

    .signature-name {
      color: var(--muted);
      font-size: 12px;
      font-weight: 400;
    }

    .print-title { display: none; }

    .protocol-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin: 10px 0 12px;
      color: var(--text);
    }

    .protocol-meta span {
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 7px 10px;
      background: #fff;
      font-size: 13px;
    }

    .protocol-meta strong {
      color: var(--muted);
      margin-right: 6px;
      text-transform: uppercase;
      font-size: 11px;
    }

    @media (max-width: 980px) {
      .app-shell { grid-template-columns: 1fr; }
      aside { position: static; }
      nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
      .split, .race-workspace, .stats { grid-template-columns: 1fr; }
      .podium { grid-template-columns: 1fr; }
      .live-header { display: grid; }
      .live-header h2 { font-size: 28px; }
      .live-screen { padding: 18px; }
      .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
      main { padding: 18px; }
      .topbar { display: grid; }
    }

    @media print {
      body { background: #fff; }
      aside, .topbar, .no-print, .panel.form-panel { display: none !important; }
      .app-shell { display: block; }
      main { padding: 0; }
      .page { display: none !important; }
      #race.page.active { display: block !important; }
      #live.page.active { display: block !important; }
      .race-workspace { display: block; }
      .panel { border: 0; box-shadow: none; padding: 0; }
      .panel:not(.printable) { display: none !important; }
      .print-title { display: block; margin-bottom: 20px; }
      .print-title h1 { text-align: center; font-size: 18px; }
      .print-title p { text-align: center; color: #333; }
      th, td { font-size: 12px; }
    }
