:root {
  color-scheme: dark;
  --bg: #0b111e;
  --panel: #131d2e;
  --inset: #0e1727;
  --line: #2a3c57;
  --text: #edf3ff;
  --muted: #a8b8d0;
  --accent: #93b4ff;
  --primary: #2853d0;
  --primary-hover: #315ddc;
  --green: #7cdbc3;
  --red: #ff9ea8;
  font: 16px/1.5 "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 88% 0%, #142448 0, transparent 38rem), var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
:where(a,button,input,select,textarea,summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1, h2 { letter-spacing: -.035em; line-height: 1.12; }
h2 { font-size: clamp(1.22rem, 1.9vw, 1.6rem); }
a { color: inherit; }
.shell { width: min(100%, 1650px); margin: auto; padding-inline: clamp(16px, 3.6vw, 64px); }
.topbar { border-bottom: 1px solid var(--line); background: #0e1928; }
.topbar-inner, .top-actions, .hero-row, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-inner { min-height: 66px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 9px; }
.brand b { font-size: 1.25rem; letter-spacing: -.04em; }
.brand-scope { padding-left: 11px; border-left: 1px solid var(--line); color: var(--muted); font-size: .84rem; }
.top-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.primary, .secondary, .edit-plan-toggle, .quick-time button, .save-plan {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-align: center;
  text-decoration: none;
  font-weight: 680;
  font-size: .875rem;
}
.primary, .save-plan { border-color: var(--primary); background: var(--primary); color: #fff; }
.primary:hover, .save-plan:hover { background: var(--primary-hover); }
.secondary, .edit-plan-toggle, .quick-time button { background: var(--inset); color: var(--text); }
.secondary:not(:disabled):hover, .edit-plan-toggle:hover, .quick-time button:hover { border-color: #5676a6; background: #1b2c47; }
.main-shell { padding-block: 28px 56px; }
.login-card {
  width: min(100%, 452px);
  margin: clamp(12px, 8vh, 100px) auto 0;
  padding: clamp(24px, 4vw, 40px);
  border: 1px solid var(--line);
  border-top: 3px solid var(--primary);
  border-radius: 12px;
  background: var(--panel);
}
.login-card h1 { font-size: clamp(2rem, 5vw, 2.7rem); }
.login-card > p { margin-top: 10px; color: var(--muted); }
.login-card form { display: grid; gap: 8px; margin-top: 23px; }
.login-card form > label:not(.check-row):not(:first-child) { margin-top: 6px; }
.login-card form > .primary { margin-top: 10px; }

label { display: grid; gap: 7px; min-width: 0; font-weight: 650; font-size: .875rem; }
input:not([type="checkbox"]), select, textarea {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--inset);
}
.password-entry input:not([type="checkbox"]) { padding-inline-end: 50px; }
input::placeholder, textarea::placeholder { color: #8a9bb6; }
textarea { min-height: 130px; resize: vertical; }
.check-row { display: flex; align-items: center; gap: 9px; min-height: 38px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.message { color: var(--accent); overflow-wrap: anywhere; }
.message:not(:empty) { margin: 10px 0; }
.message:empty { display: none; }

.workspace { display: grid; grid-template-columns: minmax(190px, 232px) minmax(0, 1fr); gap: clamp(16px, 2.2vw, 34px); align-items: start; }
.workspace-sidebar { position: sticky; top: 18px; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.workspace-product { display: grid; gap: 7px; padding: 4px 4px 12px; }
.environment { color: var(--muted); font-size: .81rem; }
.environment.is-dev { color: #ffda9d; }
.workspace-nav { display: grid; gap: 5px; border-top: 1px solid var(--line); padding-top: 10px; }
.workspace-nav button {
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 680;
  text-align: left;
}
.workspace-nav button:hover { background: #1b2940; color: var(--text); }
.workspace-nav button[aria-current="page"] { border-color: #4164ac; background: #1c315b; color: #e5edff; }
.workspace-content { min-width: 0; }
.hero-row { align-items: flex-end; margin: 0 0 20px; }
.hero-row h1 { font-size: clamp(2.1rem, 5vw, 3.8rem); }
.product-name { margin-bottom: 5px; color: var(--accent); font-size: .92rem; font-weight: 700; }
.muted, .panel-head p { color: var(--muted); }
#updatedAt { margin-top: 7px; font-size: .81rem; }
.workspace-section { display: grid; gap: 16px; }

.metrics, .month-totals { display: grid; gap: 12px; grid-template-columns: repeat(4,minmax(0,1fr)); }
.manager-metrics, .month-totals { grid-template-columns: repeat(3,minmax(0,1fr)); }
.metrics article, .month-totals article {
  min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.metrics article:first-child { background: linear-gradient(135deg,#1b315a,#152337); border-color: #365a97; }
.metrics span, .metrics small, .month-totals span, .month-totals small { display: block; color: var(--muted); font-size: .82rem; }
.metrics strong, .month-totals strong {
  display: block; margin: 7px 0; font-size: clamp(1.28rem, 2.1vw, 2rem);
  font-variant-numeric: tabular-nums; line-height: 1.12; overflow-wrap: anywhere;
}
.panel { min-width: 0; padding: clamp(16px, 2.5vw, 29px); border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.panel-head { align-items: flex-start; margin-bottom: 16px; }
.panel-head p { margin-top: 5px; font-size: .9rem; }
.month-controls { display: flex; flex: 0 1 auto; align-items: end; gap: 7px; }
.month-controls label { min-width: min(175px, 34vw); }
.month-controls button { flex: 0 0 44px; min-height: 44px; font-size: 1.25rem; line-height: 1; }
.month-totals article { background: var(--inset); }
.month-totals dl { display: grid; gap: 5px; margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.month-totals dl div { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }
.month-totals dd { margin: 0; text-align: right; }
.month-totals dt { color: var(--muted); }
.zero-month { grid-column: 1/-1; }

.payment-list, .announcement-history, .customer-list { display: grid; gap: 9px; }
.payment-list article, .announcement-history article {
  display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr); gap: 10px 16px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--inset);
  overflow-wrap: anywhere;
}
.payment-list :is(strong,small,b,time) { display: block; }
.payment-list time, .payment-list small, .announcement-history small { color: var(--muted); font-size: .8rem; }
.payment-list article > div:last-child, .announcement-history article > small { text-align: right; }
.announcement-history p { color: var(--muted); margin-top: 5px; white-space: pre-wrap; }

.customer-filters { display: grid; grid-template-columns: minmax(0,2fr) minmax(135px,1fr); gap: 12px; margin-bottom: 16px; }
.customer-card { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--inset); }
.customer-card > header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.customer-identity { display: flex; align-items: flex-start; gap: 11px; min-width: 0; overflow-wrap: anywhere; }
.customer-identity > :is(img,span) {
  display: grid; place-items: center; flex: 0 0 42px; width: 42px; height: 42px; object-fit: cover;
  border-radius: 8px; background: #20375d; color: #c1d4ff; font-weight: 800; font-size: .82rem;
}
.customer-card :is(small,em) { display: block; color: var(--muted); font-size: .8125rem; font-style: normal; }
.customer-plan-summary { display: flex; align-items: flex-end; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.customer-plan-summary small { padding-bottom: 7px; }
.badge { align-self: center; padding: 4px 9px; border-radius: 5px; background: #20375d; color: #d5e3ff; font-size: .81rem; font-weight: 700; }
.edit-plan-toggle { min-height: 38px; color: var(--accent); background: #14243c; }
.customer-meta { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(155px,100%),1fr)); gap: 7px; margin-top: 13px; }
.customer-meta > span { padding: 9px; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; font-size: .86rem; }
.customer-meta b { display: block; margin-bottom: 2px; color: var(--muted); font-size: .77rem; }
.customer-meta code { color: #c6d7ff; font-size: .81rem; }
.customer-meta button { min-height: 34px; padding: 4px; border: 0; background: transparent; color: var(--accent); font-size: .82rem; }
.status { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.status.off { background: var(--red); }
.plan-editor {
  display: grid; grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 11px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.quick-time { grid-column: 1/-1; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--muted); font-size: .85rem; }
.quick-time button { min-height: 40px; padding: 7px 10px; }
.manager-plan-editor { margin-top: 13px; }
.manager-plan-editor summary { color: var(--accent); font-size: .875rem; font-weight: 700; }
.manager-plan-editor form { display: flex; align-items: end; flex-wrap: wrap; gap: 8px 12px; margin-top: 10px; }
.manager-plan-editor label { flex: 1 0 min(180px, 100%); }
.manager-plan-editor small { flex-basis: 100%; }
.save-plan { justify-self: start; grid-column: 1/-1; }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.settings-grid .wide, .form-actions { grid-column: 1/-1; }
.settings-grid .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 4px; }
.roles-panel summary { font-weight: 720; }
.roles-panel[open] summary { margin-bottom: 14px; }
.role-list { display: flex; flex-wrap: wrap; gap: 7px; }
.role-list span {
  display: flex; flex-wrap: wrap; gap: 7px; padding: 7px 10px; max-width: 100%;
  border: 1px solid var(--line); border-radius: 6px; color: var(--muted); overflow-wrap: anywhere;
}
.empty, .empty-inline { padding: 18px 10px; color: var(--muted); }
.payment-history-dialog {
  width: min(660px, calc(100% - 24px)); max-height: 85dvh; padding: clamp(16px, 3vw, 26px);
  color: var(--text); background: var(--panel); border: 1px solid #42618b; border-radius: 11px;
}
.payment-history-dialog::backdrop { background: #080d18d6; }
.payment-history-dialog header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.payment-history-dialog p { margin: 7px 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.payment-history-dialog p:empty { display: none; }

@media (max-width: 1120px) {
  .metrics:not(.manager-metrics) { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .hero-row { align-items: flex-start; flex-wrap: wrap; }
}
@media (max-width: 780px) {
  .workspace { grid-template-columns: minmax(0,1fr); }
  .workspace-sidebar { display: contents; }
  .workspace-product, .workspace-nav { padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
  .workspace-product { grid-template-columns: auto minmax(0,1fr); align-items: center; }
  #adminSectionTitle { scroll-margin-top: 140px; }
  .workspace-product .environment { grid-column: 2; }
  .workspace-nav { position: sticky; top: 6px; z-index: 5; grid-template-columns: repeat(4,minmax(0,1fr)); }
  .workspace-nav button { text-align: center; }
}
@media (max-width: 510px) {
  .main-shell { padding-top: 16px; }
  .topbar-inner { min-height: 60px; gap: 8px; }
  .brand { gap: 6px; }
  .brand img { width: 30px; height: 30px; }
  .brand-scope { padding-left: 6px; }
  .topbar .secondary { min-height: 36px; padding: 6px 9px; font-size: .8rem; }
  .workspace-nav { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .hero-row { margin-bottom: 14px; }
  .hero-row .top-actions { width: 100%; justify-content: flex-start; }
  .panel-head { display: grid; gap: 11px; }
  .month-controls label { min-width: 0; width: 100%; }
  .month-controls button { min-width: 38px; flex-basis: 38px; }
  .manager-metrics, .month-totals, .customer-filters, .settings-grid { grid-template-columns: 1fr; }
  .metrics article, .month-totals article { padding: 12px; }
  .customer-card > header { align-items: flex-start; flex-direction: column; }
  .customer-plan-summary { justify-content: flex-start; align-items: center; }
  .customer-plan-summary small { padding: 0; }
  .customer-meta { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .customer-meta:has(code) > span:has(code) { grid-column: 1/-1; }
  .save-plan { width: 100%; }
}
