@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600;700;800;900&family=Cinzel+Decorative:wght@400;700;900&family=Inter:wght@400;500;600;700;800;900&display=swap');

/* O2 PRIME — ROYAL DARK MEDIEVAL KINGDOM THEME
   Visual-only layer. Existing routes, API calls, auth and business logic remain untouched. */
:root {
  --purple: #c49a4a;
  --purple2: #f0c46c;
  --purple-soft: rgba(201,164,91,.16);
  --ink: #f2eadb;
  --muted: #b6aa96;
  --line: #4a3b27;
  --bg: #100f0d;
  --white: #211d17;
  --radius: 15px;
  --shadow: 0 14px 38px rgba(0,0,0,.32);
  --royal-black: #100f0d;
  --royal-obsidian: #181511;
  --royal-panel: #211c16;
  --royal-panel-2: #2a231a;
  --royal-gold: #c9a45b;
  --royal-gold-bright: #f4d28a;
  --royal-burgundy: #5b1825;
  --royal-emerald: #174b3a;
}

html, body { min-height: 100%; }
body {
  background: var(--royal-black);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font-family: Inter, ui-sans-serif, system-ui, sans-serif; }

/* LOGIN — full-bleed castle artwork + real HTML login controls */
#loginView.royal-login-view {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(420px, .88fr);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: #f7edda;
  background-color: #090908;
  background-image:
    linear-gradient(90deg, rgba(5,5,5,.10) 0%, rgba(6,6,6,.02) 43%, rgba(8,7,6,.43) 59%, rgba(8,7,6,.90) 100%),
    url("../images/royal-kingdom-login.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}
#loginView .royal-login-brand {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  padding: clamp(24px, 4vw, 60px);
  background: transparent;
  overflow: visible;
}
#loginView .royal-login-brand::after { content: none; }
#loginView .royal-login-logo {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  align-self: flex-start;
  width: max-content;
  max-width: 100%;
  padding: 8px 17px 8px 8px;
  border: 1px solid rgba(213,177,101,.48);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(14,12,9,.82), rgba(30,22,12,.58));
  box-shadow: 0 8px 28px rgba(0,0,0,.28), inset 0 1px rgba(255,235,187,.08);
  color: #fff1d2;
  font: 700 17px Cinzel, Georgia, serif;
  letter-spacing: .035em;
  text-shadow: 0 2px 4px #000;
  z-index: 2;
}
#loginView .royal-crest-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 1px solid #e4bd69;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 36%, #f5d88f 0, #9d722c 34%, #28190b 67%, #100d09 100%);
  color: #fff1c5;
  font: 900 17px Cinzel, Georgia, serif;
  box-shadow: 0 0 0 3px rgba(201,164,91,.14), 0 0 24px rgba(214,159,58,.26), inset 0 0 0 2px rgba(255,225,151,.22);
  text-shadow: 0 1px 3px #211;
}
#loginView .royal-brand-name { white-space: nowrap; }
#loginView .royal-login-wordmark {
  position: relative;
  z-index: 1;
  align-self: flex-start;
  margin: 0 0 8px 4px;
  color: #eac77e;
  font: 900 clamp(35px, 5.8vw, 78px)/.95 "Cinzel Decorative", Cinzel, Georgia, serif;
  letter-spacing: -.045em;
  text-shadow: 0 3px 0 #4b2b0c, 0 6px 14px rgba(0,0,0,.9), 0 0 24px rgba(216,154,47,.28);
  -webkit-text-stroke: .5px rgba(255,224,153,.45);
}
#loginView .royal-wordmark-rule {
  display: block;
  width: min(370px, 54vw);
  height: 1px;
  margin: 0 0 13px;
  background: linear-gradient(90deg, transparent, #e6c77e 20%, #9a6d2c 75%, transparent);
  box-shadow: 0 0 9px rgba(226,178,79,.45);
}
#loginView .royal-login-wordmark small {
  display: block;
  margin: 12px 0 0 5px;
  color: rgba(246,222,174,.82);
  font: 700 10px Inter, sans-serif;
  letter-spacing: .34em;
  text-shadow: 0 2px 4px #000;
}
#loginView .royal-login-form-side {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: clamp(24px, 4vw, 66px);
  background: linear-gradient(90deg, rgba(8,7,6,.06), rgba(8,7,6,.44) 18%, rgba(8,7,6,.82) 100%);
}
#loginView .royal-login-card {
  position: relative;
  width: min(450px, 100%);
  padding: 45px clamp(25px, 3vw, 42px) 27px;
  border: 1px solid rgba(219,181,105,.80);
  border-radius: 5px;
  color: #f3e8d2;
  background:
    linear-gradient(145deg, rgba(56,47,34,.97), rgba(30,26,20,.98) 56%, rgba(42,32,22,.98));
  box-shadow: 0 25px 75px rgba(0,0,0,.72), 0 0 0 4px rgba(10,9,7,.78), 0 0 0 6px rgba(182,139,65,.42), inset 0 0 30px rgba(0,0,0,.38), inset 0 1px rgba(255,235,184,.18);
}
#loginView .royal-login-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px solid rgba(218,183,112,.38);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.24);
}
#loginView .royal-login-card::after {
  content: "✦";
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border: 1px solid #e0bd72;
  border-radius: 50%;
  color: #ffe5a6;
  background: radial-gradient(circle, #705025, #21170c 72%);
  box-shadow: 0 4px 12px #0009, 0 0 0 4px rgba(10,8,6,.88);
  font-size: 21px;
}
#loginView .royal-card-crest {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
}
#loginView .royal-card-kicker {
  margin: 0 0 12px;
  text-align: center;
  color: #d7b46e;
  font: 800 9px Inter, sans-serif;
  letter-spacing: .28em;
}
#loginView .royal-login-card h2 {
  margin: 0 0 10px;
  color: #f6d991;
  text-align: center;
  font: 700 clamp(25px, 2.3vw, 32px)/1.18 "Cinzel Decorative", Cinzel, Georgia, serif;
  letter-spacing: -.025em;
  text-shadow: 0 2px 4px #000, 0 0 16px rgba(216,174,91,.14);
}
#loginView .royal-login-card .subtitle {
  margin: 0 0 27px;
  color: #c9bda8;
  text-align: center;
  font: 400 12px/1.65 Inter, sans-serif;
}
#loginView .royal-login-card .field { gap: 7px; margin: 0 0 16px; }
#loginView .royal-login-card .field label {
  color: #d2b77e;
  font: 700 10px Cinzel, Georgia, serif;
  letter-spacing: .10em;
  text-transform: uppercase;
}
#loginView .royal-login-card .field input {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #70552d;
  border-radius: 3px;
  color: #f8eedc;
  background: linear-gradient(180deg, #171511, #0e0d0b);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.58), 0 1px rgba(255,226,165,.08);
  font: 500 13px Inter, sans-serif;
}
#loginView .royal-login-card .field input::placeholder { color: #847a6b; }
#loginView .royal-login-card .field input:focus {
  border-color: #edc879;
  outline: none;
  box-shadow: 0 0 0 2px rgba(208,165,82,.18), inset 0 2px 8px rgba(0,0,0,.62);
}
#loginView .royal-login-submit {
  position: relative;
  width: 100%;
  min-height: 48px;
  margin-top: 7px;
  border: 1px solid #f3d38a;
  border-radius: 4px;
  color: #241707;
  background: linear-gradient(180deg, #f5d68f 0%, #c78b31 48%, #89551d 100%);
  box-shadow: inset 0 1px rgba(255,255,255,.48), inset 0 -2px rgba(70,37,6,.32), 0 5px 12px rgba(0,0,0,.42);
  font: 800 12px Cinzel, Georgia, serif;
  letter-spacing: .05em;
  text-shadow: 0 1px rgba(255,235,190,.35);
}
#loginView .royal-login-submit:hover { filter: brightness(1.12); transform: translateY(-1px); }
#loginView .royal-login-submit:active { transform: translateY(0); }
#loginView #loginError { min-height: 14px; margin: 9px 0 0; color: #ffb2a7; }
#loginView .royal-login-hint {
  margin-top: 17px;
  padding: 12px 13px;
  border: 1px solid rgba(200,160,83,.60);
  border-radius: 3px;
  color: #d8c8ac;
  background: linear-gradient(135deg, rgba(25,20,14,.9), rgba(52,38,22,.78));
  box-shadow: inset 0 1px rgba(255,228,174,.08);
  font: 400 10px/1.55 Inter, sans-serif;
}
#loginView .royal-login-hint b { color: #f0cc80; font-family: Cinzel, Georgia, serif; }
#loginView .royal-login-hint .small { color: #b8a78b; }
#loginView .royal-card-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 20px 0 0;
  color: rgba(209,180,122,.72);
  font: 700 8px Inter, sans-serif;
  letter-spacing: .17em;
  text-align: center;
}
#loginView .royal-card-footer span { width: 23px; height: 1px; background: linear-gradient(90deg, transparent, #a37b3a); }
#loginView .royal-card-footer span:last-child { transform: rotate(180deg); }

/* APP CHROME — consistent royal theme across Admin and Agent pages */
.app-shell { background: var(--royal-black); }
.topbar {
  min-height: 78px;
  height: auto;
  padding: 10px clamp(16px, 2.5vw, 38px);
  border-bottom: 1px solid rgba(196,155,78,.42);
  background: linear-gradient(180deg, #211b13, #13110e 88%);
  box-shadow: 0 8px 25px rgba(0,0,0,.32);
}
.topbar .brand {
  border: 1px solid rgba(207,169,94,.44);
  background: linear-gradient(135deg, rgba(12,11,9,.96), rgba(43,31,17,.92));
  box-shadow: 0 7px 22px rgba(0,0,0,.32), inset 0 1px rgba(255,226,166,.08);
}
.topbar .brand-name { color: #f6e5be!important; font-family: Cinzel, Georgia, serif; letter-spacing: .02em; }
.topbar .brand-sub { color: #b7a88e!important; }
.topbar .brand-mark.topbar-brand-logo { border-color: #b9914d; box-shadow: 0 0 16px rgba(205,151,53,.25); }
.top-actions { gap: 9px; }
.o2-toolbar-btn, .top-actions .btn-light, .top-actions .btn-outline {
  border: 1px solid rgba(195,151,72,.42);
  color: #ebc875;
  background: linear-gradient(180deg, #342817, #21190f);
  box-shadow: inset 0 1px rgba(255,228,173,.08), 0 3px 10px rgba(0,0,0,.18);
}
.user-pill { border: 1px solid rgba(195,151,72,.36); background: #211b13; color: #f4e6cb; }
.user-name { color: #f4e6cb; }
.user-role { color: #b9a47d; }
.avatar { color: #ffe2a0; background: linear-gradient(135deg, #80551d, #38230d); border: 1px solid #bc9146; }

.layout {
  max-width: 1720px;
  grid-template-columns: 246px minmax(0,1fr);
  gap: 22px;
  padding: 23px clamp(14px, 2.4vw, 34px);
}
.sidebar {
  border: 1px solid rgba(190,150,78,.38);
  border-radius: 17px;
  padding: 13px;
  background:
    linear-gradient(155deg, rgba(42,33,22,.98), rgba(23,21,17,.98) 72%),
    radial-gradient(circle at 20% 0%, rgba(191,145,60,.12), transparent 50%);
  box-shadow: 0 15px 35px rgba(0,0,0,.28), inset 0 1px rgba(255,225,165,.08);
}
.nav-label { color: #c8a96b; font-family: Cinzel, Georgia, serif; letter-spacing: .16em; }
.nav-btn {
  margin: 3px 0;
  padding: 12px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #d4c6ae;
  background: transparent;
  font-weight: 650;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.nav-btn:hover:not(.o2-disabled-nav) {
  color: #ffe2a1;
  border-color: rgba(200,161,91,.28);
  background: rgba(190,145,62,.10);
  transform: translateX(2px);
}
.nav-btn.active {
  color: #ffe2a1;
  border-color: rgba(227,184,101,.62);
  background: linear-gradient(100deg, rgba(113,73,24,.68), rgba(65,45,20,.68));
  box-shadow: inset 3px 0 #e2b95f, inset 0 1px rgba(255,226,171,.08), 0 5px 14px rgba(0,0,0,.18);
}
.nav-btn .nav-icon { color: #d5ae63; }
.sidebar-foot { color: #9d907a; border-top-color: rgba(190,150,78,.25); }

.content { color: #eee5d6; }
.page-head h1, .panel-title, .task-title, .modal-head h2 {
  color: #f0dfba;
  font-family: Cinzel, Georgia, serif;
  letter-spacing: .01em;
}
.page-head h1 { font-size: clamp(22px, 2vw, 30px); }
.page-head p, .panel-note, .note-row { color: #b7aa96; }
.kpi, .panel, .task-card, .empty-card, .race-history {
  color: #eee5d6;
  border: 1px solid rgba(177,139,73,.34);
  background: linear-gradient(145deg, rgba(39,33,25,.98), rgba(27,25,21,.98));
  box-shadow: 0 10px 28px rgba(0,0,0,.24), inset 0 1px rgba(255,230,182,.045);
}
.kpi { position: relative; overflow: hidden; }
.kpi::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(222,179,91,.72), transparent);
}
.kpi-top { color: #c7b99e; }
.kpi-icon, .task-number {
  color: #f5d48b;
  border: 1px solid rgba(201,164,91,.35);
  background: linear-gradient(135deg, #58401e, #2a1d0c);
}
.kpi-value { color: #fff0d1; }
.kpi-foot { color: #a99b83; }

/* Forms, tables and buttons */
.field label { color: #d0b77f; }
.field input, .field select, .field textarea,
.task-actions input, .task-actions textarea,
.final-box input[type=text], .final-box input[type=file] {
  border-color: #5b482c;
  color: #f1e8d8;
  background: #15130f;
}
.field input::placeholder, .field textarea::placeholder { color: #857965; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: #d7b36a;
  box-shadow: 0 0 0 3px rgba(201,164,91,.16);
}
.btn-primary {
  color: #251908;
  border: 1px solid #e6bf70;
  background: linear-gradient(180deg, #f1d18a, #c38a35 56%, #8d5a21);
  box-shadow: inset 0 1px rgba(255,255,255,.35), 0 5px 15px rgba(0,0,0,.28);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-outline, .btn-light {
  color: #e9c577;
  border: 1px solid #6a512c;
  background: linear-gradient(180deg, #342a1b, #221a10);
}
.btn-danger { color: #ffd1ce; border: 1px solid #74343a; background: #421e20; }
.btn-green { color: #c7eed4; border: 1px solid #2e6548; background: #193b2a; }
.table-wrap { border: 1px solid rgba(190,150,78,.34); background: #181612; }
table { color: #e8dfd0; background: #1d1a15; }
th { color: #ebca83; background: linear-gradient(180deg, #382c1b, #292116); border-bottom: 1px solid #6c512c; }
td { color: #e6ddcf; border-bottom-color: rgba(183,145,82,.20); }
tr:hover td { background: rgba(194,150,70,.055); }
.status-pill { border: 1px solid rgba(255,255,255,.08); }
.status-green { color: #bde8cb; background: #1a3d2b; }
.status-orange { color: #ffdf9c; background: #4a3418; }
.status-red { color: #ffc4c4; background: #4a2024; }
.status-blue { color: #c2dfff; background: #1c3447; }
.status-purple { color: #e4d1ff; background: #382447; }
.status-gray { color: #d4c9b8; background: #39342c; }
.banner-warning { color: #f1d69d; border-color: #705322; background: #3b2c17; }
.banner-info { color: #c8d9e7; border-color: #3a566a; background: #1c303b; }
.banner-success { color: #c2e7d0; border-color: #356348; background: #183b2a; }
.progress-track { background: #3b3327; }
.progress-fill { background: linear-gradient(90deg, #8a5a1f, #dfb65f, #f6d995); }
.modal-backdrop { background: rgba(0,0,0,.76); backdrop-filter: blur(5px); }
.modal { color: #efe4d0; border: 1px solid #846536; background: linear-gradient(145deg, #2b241a, #171511); box-shadow: 0 24px 70px rgba(0,0,0,.66); }
.modal-head { border-bottom: 1px solid rgba(191,150,77,.24); }
.modal-close { color: #e9cb89; background: #3b2d1b; }
.toast { color: #f7ecd7; border: 1px solid rgba(218,179,102,.3); background: #2b2318; }
.toast.success { background: #173b2a; }
.toast.error { background: #4a2024; }
.empty-state, .empty-card { color: #c4b7a2; }
.loading { color: #c4b28c; }

/* Dark-mode toggle remains compatible; the kingdom palette stays consistent. */
body.dark-mode { background: var(--royal-black); color: var(--ink); }
body.dark-mode .topbar, body.dark-mode .sidebar, body.dark-mode .panel, body.dark-mode .kpi,
body.dark-mode .task-card, body.dark-mode .empty-card, body.dark-mode .modal,
body.dark-mode .table-wrap, body.dark-mode table, body.dark-mode th,
body.dark-mode .field input, body.dark-mode .field select, body.dark-mode .field textarea,
body.dark-mode .btn-outline { background-color: #211d17; color: #eee5d6; border-color: #4a3b27; }
body.dark-mode th { background: #342919; color: #ebca83; }
body.dark-mode .nav-btn { color: #d4c6ae; }
body.dark-mode .nav-btn.active { color: #ffe2a1; background: linear-gradient(100deg, rgba(113,73,24,.68), rgba(65,45,20,.68)); }

@media (max-width: 900px) {
  #loginView.royal-login-view { grid-template-columns: minmax(0,1fr) minmax(360px,.9fr); background-position: 43% center; }
  #loginView .royal-login-brand { padding: 25px; }
  #loginView .royal-login-form-side { padding: 22px; }
  #loginView .royal-login-wordmark { font-size: clamp(34px,5vw,58px); }
}
@media (max-width: 680px) {
  #loginView.royal-login-view {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow: auto;
    background-image:
      linear-gradient(180deg, rgba(5,5,5,.10) 0%, rgba(8,7,6,.25) 34%, rgba(8,7,6,.92) 62%, #080807 100%),
      url("../images/royal-kingdom-login.png");
    background-size: auto 100%, auto 100%;
    background-position: 37% top;
    background-attachment: scroll;
  }
  #loginView .royal-login-brand { flex: 0 0 auto; min-height: 145px; padding: 18px 18px 10px; }
  #loginView .royal-login-logo { padding: 6px 12px 6px 6px; font-size: 14px; }
  #loginView .royal-crest-mark { width: 39px; height: 39px; flex-basis: 39px; font-size: 14px; }
  #loginView .royal-login-wordmark { display: none; }
  #loginView .royal-login-form-side { flex: 1 0 auto; align-items: flex-end; padding: 18px 16px 26px; background: linear-gradient(180deg, transparent, rgba(7,7,6,.88) 15%, #080807 100%); }
  #loginView .royal-login-card { width: min(440px,100%); padding: 39px 23px 23px; }
  #loginView .royal-login-card h2 { font-size: 24px; }
  #loginView .royal-login-card .subtitle { margin-bottom: 20px; }
  .layout { display: block; padding: 13px 10px; }
  .sidebar { position: relative; top: auto; margin-bottom: 15px; display: flex; overflow-x: auto; white-space: nowrap; }
  .nav-btn { width: auto; flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
