:root {
  --ink: #171b18;
  --muted: #697169;
  --paper: #f3f5f0;
  --surface: #ffffff;
  --line: #d8ddd7;
  --line-dark: #343d36;
  --sidebar: #19201b;
  --sidebar-soft: #252d27;
  --coral: #e85b3e;
  --coral-dark: #bd3f28;
  --green: #287653;
  --yellow: #d6a62e;
  --blue: #3f6e8e;
  --danger: #bf3f36;
  --radius: 6px;
  --sidebar-width: 228px;
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--paper); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .58; }
[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f8faf6;
  background-color: var(--sidebar);
  background-image:
    linear-gradient(#2f3932 1px, transparent 1px),
    linear-gradient(90deg, #2f3932 1px, transparent 1px);
  background-size: 40px 40px;
}

.login-panel {
  position: relative;
  width: min(100%, 420px);
  padding: 34px 36px 38px;
  background: #202822;
  border: 1px solid #3b463e;
  border-radius: var(--radius);
  box-shadow: 18px 18px 0 #111512;
  overflow: hidden;
}

.login-brand, .sidebar-brand { display: flex; align-items: center; gap: 11px; }
.login-brand { font: 700 15px/1 "DIN Alternate", "Avenir Next", sans-serif; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--coral);
  border-radius: 4px;
}
.brand-mark svg { width: 19px; height: 19px; }
.login-heading { margin: 56px 0 30px; }
.eyebrow, .section-index, .section-meta {
  font: 700 11px/1.2 "DIN Alternate", "Avenir Next", sans-serif;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.eyebrow { color: var(--coral); }
.login-heading h1 { margin: 8px 0 0; font-size: 28px; line-height: 1.2; }
.login-form { display: grid; gap: 18px; }
.login-form label, .field { display: grid; gap: 7px; }
.login-form label span, .field span, .field-label {
  color: #b9c1ba;
  font-size: 12px;
  font-weight: 650;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #cbd1ca;
  border-radius: 4px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(40 118 83 / 12%);
}
textarea { resize: vertical; }
.login-form input { color: #fff; background: #151a17; border-color: #465149; }
.login-form input:focus { border-color: var(--coral); box-shadow: 0 0 0 3px rgb(232 91 62 / 15%); }
.login-stripe { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--coral); }
.form-error { min-height: 18px; margin: -4px 0 0; color: #ff9c87; font-size: 12px; }

.button, .icon-button, .text-button, .nav-item {
  border: 0;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.button { min-height: 40px; padding: 0 15px; font-size: 13px; font-weight: 700; }
.button svg, .nav-item svg { width: 17px; height: 17px; }
.button-primary { color: #fff; background: var(--coral); }
.button-primary:hover { background: var(--coral-dark); }
.button-secondary { color: var(--ink); background: #e4e8e2; border: 1px solid #cfd5ce; }
.button-secondary:hover { background: #dbe1da; }
.button-ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.button-danger { color: #fff; background: var(--danger); }
.button-wide { width: 100%; }
.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}
.icon-button:hover { border-color: #929b93; }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.inverse { color: #fff; background: #2b342d; border-color: #4a564d; }
.text-button { padding: 4px 0; color: var(--green); background: none; font-size: 12px; font-weight: 750; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  color: #e9ede8;
  background: var(--sidebar);
  border-right: 1px solid #303a33;
}
.sidebar-brand { padding: 0 9px 27px; color: inherit; text-decoration: none; }
.brand-copy { display: grid; gap: 3px; }
.brand-copy strong { font: 700 14px/1 "DIN Alternate", "Avenir Next", sans-serif; }
.brand-copy small { color: #8f9a91; font-size: 10px; }
.sidebar-nav { display: grid; gap: 5px; }
.nav-item {
  width: 100%;
  min-height: 43px;
  justify-content: flex-start;
  padding: 0 12px;
  color: #aeb7b0;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
}
.nav-item:hover { color: #fff; background: #222b24; }
.nav-item.active { color: #fff; background: var(--sidebar-soft); box-shadow: inset 3px 0 var(--coral); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.service-state { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #aeb7b0; font-size: 10px; }
.service-state span { width: 7px; height: 7px; background: #59c58b; border-radius: 50%; box-shadow: 0 0 0 4px rgb(89 197 139 / 10%); }
.service-state strong { font-weight: 650; }
.logout-button { border-top: 1px solid #303a33; border-radius: 0; }

.workspace { grid-column: 2; min-width: 0; padding: 0 34px 50px; }
.topbar {
  min-height: 106px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 6px 0 0; font-size: 24px; line-height: 1.15; }
.topbar-actions { display: flex; align-items: center; gap: 13px; }
.current-user { color: var(--muted); font-size: 12px; }
.account-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
}
.account-button:hover { color: var(--ink); background: var(--surface); border-color: var(--line); }
.account-button svg { width: 16px; height: 16px; }
.view { display: none; padding-top: 28px; animation: view-in .22s ease both; }
.active-view { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-cell { min-height: 112px; padding: 20px; border-right: 1px solid var(--line); }
.stat-cell:last-child { border-right: 0; }
.stat-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.stat-label svg { width: 15px; height: 15px; }
.stat-value { display: block; margin-top: 14px; font: 700 30px/1 "DIN Alternate", "Avenir Next", sans-serif; }
.stat-foot { display: block; margin-top: 7px; color: #929992; font-size: 10px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 32px; margin-top: 34px; }
.data-section { min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.section-heading > div:first-child { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.section-heading h2 { margin: 0; font-size: 16px; line-height: 1.2; }
.section-index { color: var(--coral); }
.section-meta { color: #8a928b; white-space: nowrap; }
.request-metrics { display: grid; border-top: 1px solid var(--ink); }
.request-row { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--line); }
.request-row span { color: var(--muted); font-size: 12px; }
.request-row strong { font: 700 22px/1 "DIN Alternate", sans-serif; }
.placement-metrics { display: grid; gap: 13px; padding-top: 4px; }
.placement-row { display: grid; grid-template-columns: 142px 1fr 44px; align-items: center; gap: 12px; }
.placement-label { min-width: 0; }
.placement-label strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.placement-label small { color: var(--muted); font-size: 9px; }
.placement-track { height: 7px; background: #dfe4de; overflow: hidden; }
.placement-fill { height: 100%; min-width: 2px; background: var(--green); }
.placement-count { text-align: right; font: 700 13px/1 "DIN Alternate", sans-serif; }
.recent-section { margin-top: 38px; }

.table-wrap { width: 100%; overflow-x: auto; border-top: 1px solid var(--ink); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 41px; color: var(--muted); font-size: 10px; text-align: left; text-transform: uppercase; }
td { height: 66px; padding: 8px 8px 8px 0; border-top: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
tr:first-child td { border-top: 0; }
.ad-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.ad-thumb { width: 68px; height: 44px; flex: 0 0 68px; object-fit: cover; background: #dfe3dd; border-radius: 3px; }
.ad-thumb-placeholder { display: grid; place-items: center; color: #929a93; }
.ad-thumb-placeholder svg { width: 17px; }
.ad-copy { min-width: 0; }
.ad-copy strong, .ad-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-copy strong { font-size: 12px; }
.ad-copy small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.placement-chip, .status-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 5px 7px;
  overflow: hidden;
  color: #3f4a42;
  background: #e5e9e3;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-chip { gap: 5px; }
.status-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #8d968f; }
.status-chip.enabled { color: #1f6847; background: #e0f0e7; }
.status-chip.enabled::before { background: #2d9464; }
.status-chip.scheduled { color: #77580b; background: #f6eccb; }
.status-chip.scheduled::before { background: var(--yellow); }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.row-actions .icon-button { width: 32px; height: 32px; flex-basis: 32px; }
.switch { position: relative; width: 36px; height: 20px; display: inline-block; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: absolute; inset: 0; background: #b8bfb9; border-radius: 10px; transition: background .16s ease; }
.switch span::after { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .16s ease; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(16px); }

.inventory-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 190px 150px 38px; gap: 9px; margin-bottom: 28px; }
.search-control { position: relative; display: block; }
.search-control svg { position: absolute; left: 11px; top: 11px; width: 17px; height: 17px; color: #858d86; }
.search-control input { padding-left: 36px; }
.inventory-heading { margin-bottom: 8px; }
.inventory-table { min-height: 280px; }
.inventory-table th:nth-child(1) { width: 32%; }
.inventory-table th:nth-child(2) { width: 19%; }
.inventory-table th:nth-child(3) { width: 12%; }
.inventory-table th:nth-child(4) { width: 13%; }
.inventory-table th:nth-child(5) { width: 10%; }
.inventory-table th:nth-child(6) { width: 14%; text-align: right; }
.empty-state { min-height: 270px; display: grid; place-items: center; color: var(--muted); border-bottom: 1px solid var(--line); }
.empty-state div { text-align: center; }
.empty-state svg { width: 32px; height: 32px; margin-bottom: 9px; color: #a4aca5; }
.empty-state strong { display: block; color: var(--ink); font-size: 13px; }
.empty-state span { display: block; margin-top: 5px; font-size: 11px; }

.heading-actions { display: flex; align-items: center; gap: 12px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 15px; }
.media-item { position: relative; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.media-item img { width: 100%; aspect-ratio: 16 / 10; display: block; object-fit: cover; background: #e2e5e0; }
.media-info { padding: 10px 11px 12px; }
.media-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.media-info small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }
.media-delete { position: absolute; top: 7px; right: 7px; color: #fff; background: rgb(19 24 20 / 78%); border-color: rgb(255 255 255 / 20%); }

.integration-layout { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(0, 1.2fr); gap: 38px; }
.endpoint-section { padding-top: 8px; }
.endpoint-section h2 { margin: 8px 0 25px; font-size: 26px; }
.endpoint-box { min-height: 58px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 9px 10px 9px 13px; color: #fff; background: var(--sidebar); border-radius: var(--radius); }
.endpoint-box code { overflow: hidden; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.method-badge { padding: 5px 7px; color: #101511; background: #68d49a; border-radius: 3px; font: 800 9px/1 "DIN Alternate", sans-serif; }
.endpoint-facts { display: grid; grid-template-columns: repeat(3, 1fr); margin: 24px 0 0; border-top: 1px solid var(--ink); }
.endpoint-facts div { padding: 14px 8px 0 0; }
.endpoint-facts dt { color: var(--muted); font-size: 9px; }
.endpoint-facts dd { margin: 5px 0 0; font-size: 11px; font-weight: 700; }
.response-preview { height: 480px; margin: 0; padding: 18px; overflow: auto; color: #dfe8e0; background: #1c231e; border: 1px solid #39433b; border-radius: var(--radius); font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }

.modal { width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 30px); padding: 0; color: var(--ink); background: var(--surface); border: 1px solid #bbc2bb; border-radius: var(--radius); box-shadow: 0 24px 70px rgb(16 22 18 / 24%); }
.modal::backdrop, .account-dialog::backdrop, .confirm-dialog::backdrop { background: rgb(17 23 19 / 68%); backdrop-filter: blur(2px); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; }
.modal-header { border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 4px 0 0; font-size: 20px; }
.modal-body { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 25px; padding: 22px; overflow-y: auto; }
.form-main { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 14px; }
.field-wide { grid-column: 1 / -1; }
.field span, .field-label { color: #525b53; }
.check-field { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 12px; font-weight: 650; }
.check-field input { width: 17px; height: 17px; accent-color: var(--green); }
.form-media { min-width: 0; padding-left: 24px; border-left: 1px solid var(--line); }
.ad-image-preview { width: 100%; aspect-ratio: 16 / 10; display: grid; place-items: center; margin: 7px 0 15px; overflow: hidden; color: #8a938b; background: #e5e8e3; border: 1px dashed #abb3ac; border-radius: 4px; }
.ad-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.ad-image-preview svg { width: 28px; height: 28px; }
.form-media .field { margin-bottom: 13px; }
.modal-footer { justify-content: flex-end; border-top: 1px solid var(--line); }

.account-dialog { width: min(440px, calc(100vw - 32px)); padding: 0; color: var(--ink); background: var(--surface); border: 1px solid #bbc2bb; border-radius: var(--radius); box-shadow: 0 24px 70px rgb(16 22 18 / 24%); }
.account-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.account-header h2 { margin: 4px 0 0; font-size: 20px; }
.account-body { display: grid; gap: 15px; padding: 22px; }
.account-body .form-error { color: var(--danger); }

.confirm-dialog { width: min(400px, calc(100vw - 32px)); padding: 25px; text-align: center; border: 0; border-radius: var(--radius); }
.confirm-icon { width: 43px; height: 43px; display: grid; place-items: center; margin: 0 auto 13px; color: var(--danger); background: #f7e5e3; border-radius: 50%; }
.confirm-icon svg { width: 21px; }
.confirm-dialog h2 { margin: 0; font-size: 18px; }
.confirm-dialog p { margin: 9px 0 21px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: center; gap: 9px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(350px, calc(100vw - 36px)); }
.toast { display: grid; grid-template-columns: 20px 1fr; align-items: center; gap: 9px; padding: 12px 13px; color: #fff; background: #222a24; border-left: 4px solid #64c993; border-radius: 4px; box-shadow: 0 12px 32px rgb(15 20 16 / 20%); animation: toast-in .2s ease both; font-size: 12px; }
.toast.error { border-left-color: #ec685b; }
.toast svg { width: 17px; height: 17px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 980px) {
  .workspace { padding-inline: 24px; }
  .dashboard-grid, .integration-layout { grid-template-columns: 1fr; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-cell:nth-child(2) { border-right: 0; }
  .stat-cell:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .inventory-toolbar { grid-template-columns: 1fr 1fr 1fr 38px; }
  .modal-body { grid-template-columns: 1fr; }
  .form-media { padding: 20px 0 0; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 720px) {
  :root { --mobile-nav-height: 68px; }
  .app-shell { display: block; }
  .sidebar { inset: auto 0 0; width: 100%; height: var(--mobile-nav-height); padding: 6px 8px max(6px, env(safe-area-inset-bottom)); border: 0; border-top: 1px solid #303a33; }
  .sidebar-brand, .sidebar-footer { display: none; }
  .sidebar-nav { height: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .nav-item { min-height: 54px; padding: 4px; flex-direction: column; justify-content: center; gap: 4px; font-size: 9px; }
  .nav-item.active { box-shadow: inset 0 3px var(--coral); }
  .workspace { padding: 0 15px calc(var(--mobile-nav-height) + 26px); }
  .topbar { min-height: 88px; }
  .topbar h1 { font-size: 20px; }
  .account-button span, .topbar-actions .button span { display: none; }
  .account-button { width: 40px; padding: 0; justify-content: center; }
  .topbar-actions .button { width: 40px; padding: 0; }
  .view { padding-top: 20px; }
  .stat-strip { grid-template-columns: 1fr 1fr; }
  .stat-cell { min-height: 98px; padding: 15px; }
  .stat-value { font-size: 25px; }
  .dashboard-grid { gap: 28px; margin-top: 28px; }
  .placement-row { grid-template-columns: 108px 1fr 30px; gap: 8px; }
  .inventory-toolbar { grid-template-columns: 1fr 1fr 38px; }
  .search-control { grid-column: 1 / -1; }
  #statusFilter { min-width: 0; }
  .inventory-table table { min-width: 760px; }
  .media-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .heading-actions .section-meta { display: none; }
  .endpoint-facts { grid-template-columns: 1fr; }
  .response-preview { height: 390px; }
  .form-main { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .modal { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .modal form { max-height: calc(100vh - 18px); }
  .modal-header, .modal-footer { padding: 14px; }
  .modal-body { padding: 15px; }
}

@media (max-width: 430px) {
  .login-panel { padding-inline: 24px; box-shadow: 10px 10px 0 #111512; }
  .stat-strip { grid-template-columns: 1fr; }
  .stat-cell { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat-cell:last-child { border-bottom: 0; }
  .media-grid { grid-template-columns: 1fr; }
  .endpoint-box { grid-template-columns: auto minmax(0, 1fr); }
  .endpoint-box .icon-button { grid-column: 1 / -1; width: 100%; }
}

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