:root {
  --ink: #172033;
  --muted: #697386;
  --line: #dfe4ea;
  --soft: #f4f6f8;
  --surface: #ffffff;
  --navy: #16263f;
  --navy-2: #203957;
  --orange: #f27a2b;
  --orange-dark: #d85f16;
  --blue: #2f6fed;
  --green: #16865c;
  --red: #c43c3c;
  --amber: #a66500;
  --shadow: 0 12px 32px rgba(18, 31, 48, .09);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: linear-gradient(145deg, #f8fafc 0%, #eef2f6 100%); }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.splash, .login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
}

.splash p { margin: 0; color: var(--muted); }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--orange);
  color: white;
  font-weight: 800;
  letter-spacing: -.04em;
  box-shadow: 0 10px 26px rgba(242, 122, 43, .3);
}

.login-shell {
  grid-template-columns: minmax(300px, 430px) minmax(360px, 580px);
  padding: 40px;
  background:
    radial-gradient(circle at 12% 12%, rgba(242, 122, 43, .13), transparent 28%),
    var(--navy);
}

.login-card {
  width: 100%;
  padding: 40px;
  border-radius: 24px;
  background: white;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
}

.login-card .brand-mark { margin-bottom: 28px; }
.login-card h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.04em; }
.login-card > p { margin: 0 0 28px; color: var(--muted); line-height: 1.55; }
.login-art { color: white; padding: 44px; }
.login-art .eyebrow { color: #ffb781; }
.login-art h2 { max-width: 520px; margin: 12px 0 18px; font-size: clamp(34px, 4vw, 54px); line-height: 1.04; letter-spacing: -.05em; }
.login-art p { max-width: 520px; color: #cbd5e1; font-size: 17px; line-height: 1.7; }

.field { display: grid; gap: 7px; margin-bottom: 18px; }
.field label, .field-label { font-size: 13px; font-weight: 700; color: #4d596a; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #ccd3dc;
  border-radius: 10px;
  color: var(--ink);
  background: white;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47, 111, 237, .13); }

.button {
  min-height: 42px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--orange);
  color: white;
  font-weight: 750;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s, background .12s;
}
.button:hover { background: var(--orange-dark); transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.secondary { background: var(--navy); }
.button.secondary:hover { background: var(--navy-2); }
.button.ghost { color: var(--navy); background: #eef2f6; }
.button.ghost:hover { background: #e4e9ef; }
.button.danger { background: #fbeaea; color: var(--red); }
.button.full { width: 100%; }
.button.small { min-height: 34px; padding: 7px 11px; font-size: 13px; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 70px;
  padding: 0 max(24px, calc((100vw - 1420px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(22, 38, 63, .98);
  color: white;
  box-shadow: 0 5px 20px rgba(15, 23, 42, .16);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; }
.brand .brand-mark { width: 38px; height: 38px; border-radius: 11px; box-shadow: none; }
.nav { display: flex; align-items: center; gap: 7px; }
.nav button {
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  background: transparent;
  color: #dbe4ee;
  font-weight: 650;
}
.nav button:hover, .nav button.active { color: white; background: rgba(255, 255, 255, .1); }
.user-chip { display: flex; align-items: center; gap: 10px; color: #dbe4ee; font-size: 13px; }

.page { max-width: 1420px; margin: 0 auto; padding: 34px 24px 60px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: 30px; letter-spacing: -.04em; }
.page-heading p { margin: 7px 0 0; color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 850; color: var(--orange-dark); }

.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: minmax(300px, .8fr) minmax(460px, 1.2fr); }
.card {
  border: 1px solid rgba(211, 218, 226, .85);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-body { padding: 22px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.card-header h2, .card-header h3 { margin: 0; font-size: 17px; }
.helper { color: var(--muted); font-size: 13px; line-height: 1.55; }

.drop-zone {
  padding: 28px;
  border: 1.5px dashed #b9c3ce;
  border-radius: 13px;
  background: #f9fbfc;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover { border-color: var(--orange); background: #fff9f5; }
.drop-zone input { border: 0; padding: 8px; background: transparent; }
.drop-zone strong { display: block; margin-bottom: 6px; }
.upload-actions { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin-top: 16px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e8ecf0; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 2; background: #f5f7f9; color: #526071; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; }
tbody tr:hover { background: #fbfcfd; }
.table-empty { padding: 38px; text-align: center; color: var(--muted); }
.table-input { min-width: 104px; min-height: 34px; padding: 6px 8px; }
.check { width: 18px; min-height: 18px; accent-color: var(--orange); }

.status { display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; border-radius: 99px; background: #edf1f5; color: #566274; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.status.ready, .status.completed { color: var(--green); background: #e8f7f1; }
.status.processing, .status.queued { color: var(--blue); background: #eaf1ff; }
.status.failed { color: var(--red); background: #fdecec; }
.status.completed_with_warnings { color: var(--amber); background: #fff4df; }

.progress { height: 7px; background: #e8edf2; border-radius: 99px; overflow: hidden; min-width: 100px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), #ff9b55); border-radius: inherit; transition: width .3s; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.metric strong { display: block; margin-top: 5px; font-size: 23px; letter-spacing: -.04em; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 18px; background: white; }
.tab { border: 0; border-bottom: 3px solid transparent; padding: 14px 12px 11px; background: transparent; color: var(--muted); font-weight: 750; }
.tab.active { color: var(--orange-dark); border-bottom-color: var(--orange); }
.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar-group { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.search { max-width: 320px; }

.canvas-shell { position: relative; min-height: 560px; background: #f6f8fa; }
#preview-canvas { display: block; width: 100%; height: 560px; }
.legend { position: absolute; left: 16px; bottom: 16px; display: flex; flex-wrap: wrap; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.93); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; }
.swatch.category { background: #f27a2b; }
.swatch.context { background: #9da8b6; }
.swatch.drawing { background: #2f6fed; }

.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 11px; background: #fff4df; color: #744c00; border: 1px solid #f2d9a9; line-height: 1.5; }
.alert.error { background: #fdecec; color: #8e2828; border-color: #f1c5c5; }
.alert.success { background: #e8f7f1; color: #126747; border-color: #bce3d3; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 10px; }
.toast { max-width: 390px; padding: 13px 15px; border-radius: 11px; color: white; background: var(--navy); box-shadow: 0 15px 40px rgba(0,0,0,.22); animation: toast-in .2s ease-out; }
.toast.error { background: #9f3030; }
.toast.success { background: #147452; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

.rule-grid { display: grid; grid-template-columns: 70px 90px 160px 1fr 1fr 100px 1.4fr 70px; gap: 8px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.rule-grid.header { background: #f5f7f9; color: #526071; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.rule-grid input { min-height: 36px; padding: 6px 8px; }
.back-link { border: 0; background: none; color: var(--blue); padding: 0; font-weight: 700; }

@media (max-width: 980px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .rule-grid { grid-template-columns: 70px 80px 110px 1fr; }
  .rule-grid > :nth-child(n+5) { grid-column: span 2; }
  .rule-grid.header { display: none; }
}

@media (max-width: 680px) {
  .login-shell { padding: 18px; }
  .login-card { padding: 28px 22px; }
  .topbar { padding: 0 14px; }
  .brand > span:last-child, .user-chip span { display: none; }
  .page { padding: 24px 14px 44px; }
  .page-heading { align-items: start; flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .upload-actions { grid-template-columns: 1fr; }
  th, td { padding: 10px; }
}
