:root {
  color-scheme: light;
  --navy: #102339;
  --ink: #17212b;
  --muted: #5d6b78;
  --gold: #cf9b38;
  --paper: #f5f6f8;
  --white: #fff;
  --red: #9d2929;
  --green: #176b4d;
  --amber: #855e09;
  --line: #d8e0e7;
  --focus: #2368c4;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; line-height: 1.5; }
button, a, input, textarea, select { font: inherit; outline-offset: 3px; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--focus); }
button { min-height: 44px; border: 1px solid transparent; border-radius: 10px; padding: .65rem .9rem; font-weight: 750; cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
.hidden { display: none !important; }

.login { max-width: 520px; margin: 8vh auto; padding: 28px; background: var(--white); border: 1px solid var(--line); border-radius: 16px; }
.brand { font-weight: 850; letter-spacing: .04em; }
.brand small { display: block; font-weight: 500; letter-spacing: 0; }
.shell { width: min(100%, 1680px); margin: 0 auto; padding: 24px; }
.top { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px; background: var(--navy); color: #fff; padding: 16px 20px; border-radius: 14px; }
.mode { background: #384b5d; padding: 10px 14px; border-radius: 9px; font-weight: 850; text-align: center; }
.mode.live { background: #176b4d; }
.mode.caution { background: #855e09; }
.session { display: flex; align-items: center; gap: 10px; }
.nav { display: flex; gap: 8px; margin: 16px 0; overflow-x: auto; overflow-y: hidden; padding: 0 2px 4px; scrollbar-gutter: stable; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: .55rem .85rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--navy); font-weight: 750; text-decoration: none; white-space: nowrap; }
.nav a[aria-current=page] { background: var(--navy); color: #fff; }

.panel { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 8px 25px #19324b10; }
.toolbar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.toolbar h1 { margin: 0; }
.grow { flex: 1 1 280px; }
#content { min-width: 0; }
#content > .grid, #content > .section { width: 100%; min-width: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 18px; }
.card { min-width: 0; border: 1px solid var(--line); border-left: 5px solid var(--gold); border-radius: 12px; padding: 16px; background: #fff; }
.card h2, .card h3 { margin: .2rem 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .07em; font-size: .78rem; font-weight: 800; color: var(--muted); }
.metric { font-size: 1.8rem; font-weight: 850; color: var(--navy); }
.small { font-size: .9rem; color: var(--muted); }
.pill { display: inline-block; max-width: 100%; border-radius: 999px; background: #eef2f5; padding: 4px 9px; font-size: .82rem; font-weight: 750; margin: 4px 4px 0 0; overflow-wrap: normal; word-break: normal; }
.danger { border-left-color: var(--red); }
.warning { border-left-color: var(--amber); }
.good { border-left-color: var(--green); }
.notice, .status { margin-top: 16px; padding: 14px; border-radius: 10px; background: #edf3f8; }
.status.danger { background: #fff0f0; }
.status.good { background: #edf8f2; }

label { display: block; font-weight: 750; margin: .8rem 0 .35rem; }
input, textarea, select { width: 100%; min-height: 48px; border: 1px solid #9eacb8; border-radius: 9px; background: #fff; padding: 10px; }
textarea { min-height: 92px; }
.primary { background: var(--navy); color: #fff; }
.secondary { background: #fff; color: var(--navy); border-color: #94a3af; }
.danger-button { background: #8e2424; color: #fff; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.command-bar { margin-bottom: 22px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #f8fafb; }
.command-bar > label { margin-top: 0; color: var(--navy); }
.global-search { margin: -8px 0 22px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.global-search > label { margin-top: 0; color: var(--navy); }
.search-results { display: grid; gap: 8px; margin-top: 10px; }
.command-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
.walkthrough-form h3 { margin: 32px 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); color: var(--navy); }
.area-editor { margin: 14px 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.area-editor legend { padding: 0 8px; font-weight: 800; color: var(--navy); }
.record-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(180px,auto) auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }
.sticky-actions { position: sticky; top: 0; z-index: 3; padding: 10px; background: #fffffff2; border: 1px solid var(--line); border-radius: 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(130px,1fr)); gap: 10px; margin: 12px 0; }
.photo-grid img { width: 100%; height: 130px; object-fit: cover; border: 1px solid var(--line); border-radius: 10px; }
.photo-card { min-height: 100px; background: #f4f7f9; color: var(--navy); border-color: var(--line); overflow-wrap: anywhere; }

.section { min-width: 0; margin-top: 26px; }
.section h2 { margin-bottom: 4px; }
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; border: 1px solid var(--line); border-radius: 12px; margin-top: 18px; -webkit-overflow-scrolling: touch; }
.table { width: max-content; min-width: 100%; border-collapse: collapse; table-layout: auto; font-size: .92rem; }
.table th, .table td { min-width: 140px; padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: normal; word-break: normal; hyphens: none; }
.table th { background: #f4f7f9; color: var(--navy); white-space: nowrap; }
.table td { white-space: normal; }
.table [data-key="company_name"], .table [data-key="legal_name"], .table [data-key="organization"], .table [data-key="client_name"], .table [data-key="title"] { min-width: 220px; }
.table [data-key="qualification_status"], .table [data-key="current_stage"], .table [data-key="planned_stage"], .table [data-key="review_type"], .table [data-key="approval_level"], .table [data-key="operation_type"], .table [data-key="route"], .table [data-key="status"] { min-width: 185px; white-space: nowrap; }
.table [data-key="territory_county"], .table [data-key="vertical"], .table [data-key="purpose"], .table [data-key="training_state"] { min-width: 160px; }
.empty { padding: 42px 16px; text-align: center; color: var(--muted); }
.skeleton { height: 110px; border-radius: 12px; background: linear-gradient(90deg, #edf1f4 25%, #f8fafb 37%, #edf1f4 63%); background-size: 400% 100%; animation: load 1.4s ease infinite; }
@keyframes load { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (min-width: 1280px) {
  .grid { grid-template-columns: repeat(4, minmax(230px, 1fr)); }
}

@media (min-width: 760px) and (max-width: 1023px) {
  .shell { padding: 18px; }
  .top { grid-template-columns: 1fr auto; }
  .session { grid-column: 1 / -1; justify-content: space-between; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 759px) {
  .shell { padding: 0; }
  .top, .panel { border-radius: 0; }
  .top { grid-template-columns: 1fr; padding: 16px; }
  .panel { padding: 16px; }
  .session { align-items: flex-start; flex-direction: column; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .nav { margin: 0; padding: 12px 16px 8px; }
  .toolbar { align-items: stretch; }
  .toolbar button { width: 100%; }
  .login { min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .table { font-size: .875rem; }
  .table th, .table td { min-width: 132px; padding: 10px; }
  .table [data-key="company_name"], .table [data-key="legal_name"], .table [data-key="organization"], .table [data-key="client_name"], .table [data-key="title"] { min-width: 190px; }
  .command-row, .form-grid, .record-row { grid-template-columns: 1fr; }
  .command-row button, .sticky-actions button { width: 100%; }
  .sticky-actions { position: static; }
}
