
:root {
  color: #17181c;
  background: #f5f5f7;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --black: #090909;
  --ink: #17181c;
  --muted: #626a77;
  --muted-strong: #555d6b;
  --page: #f5f5f7;
  --surface: #ffffff;
  --soft: #eef2f8;
  --soft-strong: #e5eaf2;
  --row: #f7f9fc;
  --accent: #245fdc;
  --accent-soft: #e8eefc;
  --danger: #c53434;
  --danger-soft: #f9e9e9;
  --success: #07784d;
  --success-soft: #e5f4ed;
  --warning: #965b00;
  --warning-soft: #fff1d8;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body { margin: 0; min-width: 320px; min-height: 100vh; min-height: 100dvh; background: var(--page); color: var(--ink); }
body, button, input, select, textarea { font: inherit; }
button, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .46; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
::selection { background: #dbe6ff; color: var(--ink); }
[hidden] { display: none !important; }

.brand-icon { display: block; flex: none; color: var(--black); }
.brand-icon svg { display: block; width: 100%; height: 100%; }
.brand-icon path { fill: currentColor; }

.session-shell,
.login-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.session-status { display: grid; justify-items: center; gap: 18px; color: var(--muted); font-size: 14px; }
.session-status p { margin: 0; }
.session-icon { width: 42px; height: 40px; animation: breathe 1.6s ease-in-out infinite alternate; }

.login-card { width: calc(100vw - 48px); max-width: 480px; min-width: 0; padding: 42px; border-radius: 36px; background: var(--surface); }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-icon { width: 47px; height: 45px; }
.brand-name { margin: 0; font-size: 20px; font-weight: 760; letter-spacing: -.025em; }
.login-copy { margin-top: 46px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 720; letter-spacing: .08em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(32px, 5vw, 42px); line-height: 1.08; letter-spacing: -.04em; }
h2 { margin-bottom: 8px; font-size: 26px; line-height: 1.14; letter-spacing: -.03em; }
h3 { margin-bottom: 6px; font-size: 17px; line-height: 1.25; letter-spacing: -.01em; }
.muted { color: var(--muted); line-height: 1.65; }
.login-copy .muted { margin-bottom: 0; font-size: 14px; }
.stack-form { display: grid; gap: 10px; margin-top: 34px; }
label { display: grid; gap: 8px; color: var(--muted-strong); font-size: 13px; font-weight: 650; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 12px 15px; border: 0; border-radius: 16px;
  outline: 0; background: var(--soft); color: var(--ink); caret-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { min-height: 116px; resize: vertical; line-height: 1.55; }
.password-field { position: relative; }
.password-field input { min-height: 56px; padding-right: 76px; }
.password-toggle {
  position: absolute; top: 6px; right: 6px; min-width: 58px; min-height: 44px; padding: 0 12px;
  background: var(--surface); color: var(--muted-strong); font-size: 12px;
}
button {
  min-height: 44px; padding: 10px 17px; border: 0; border-radius: 999px;
  background: var(--soft); color: var(--ink); font-weight: 680; line-height: 1.2;
  transition: background-color 160ms ease, color 160ms ease, transform 120ms ease;
}
button.primary { background: var(--black); color: #fff; }
button.danger { background: var(--danger-soft); color: var(--danger); }
button.quiet { background: transparent; color: var(--muted-strong); }
button.wide { width: 100%; }
button:not(:disabled):active { transform: scale(.975); }
.login-submit { min-height: 56px; margin-top: 10px; }
.form-error { min-height: 20px; margin: 14px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; }

.app-shell { width: min(1240px, calc(100% - 40px)); min-height: 100vh; min-height: 100dvh; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center; gap: 24px; padding: 22px 0 16px; background: var(--page);
}
.brand { display: flex; min-width: 0; min-height: 44px; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.topbar-icon { width: 40px; height: 38px; }
.brand-copy { display: grid; min-width: 0; }
.brand-copy strong { font-size: 17px; letter-spacing: -.025em; }
.brand-copy small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.nav-pills {
  display: grid; grid-template-columns: repeat(4, minmax(76px, 1fr)); gap: 3px; min-width: 400px;
  padding: 4px; border-radius: 999px; background: var(--soft-strong);
}
.nav-pills button { min-height: 44px; padding: 8px 16px; background: transparent; color: var(--muted); font-size: 13px; }
.nav-pills button.active { background: var(--black); color: #fff; }
.account-menu { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.owner-chip { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px; background: var(--surface); color: var(--muted-strong); font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.logout-button { min-height: 44px; background: var(--black); color: #fff; font-size: 12px; }

.content { width: 100%; margin: 0 auto; padding: 30px 0 72px; }
.content:focus { outline: none; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 26px; }
.page-title { max-width: 720px; }
.page-head .eyebrow { margin-bottom: 8px; }
.page-head h1 { margin-bottom: 9px; font-size: clamp(30px, 4vw, 38px); }
.page-head p { margin-bottom: 0; }
.head-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.head-actions:empty { display: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric { min-height: 154px; padding: 22px; border-radius: 28px; background: var(--surface); }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { margin: 28px 0 6px; font-size: 38px; font-weight: 760; line-height: 1; letter-spacing: -.045em; }
.metric small { display: block; font-size: 12px; }
.panel { margin-top: 14px; padding: 22px; border-radius: 30px; background: var(--surface); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 18px; }
.panel-head p, .panel-head h3 { margin-bottom: 0; }
.plan-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.plan-cell { min-height: 120px; padding: 18px; border-radius: 22px; background: var(--row); }
.plan-cell.care_plus { background: var(--accent-soft); }
.plan-cell.king { background: #f1ede4; }
.plan-cell strong { display: block; margin-top: 26px; font-size: 30px; line-height: 1; letter-spacing: -.04em; }

.filters {
  display: grid; grid-template-columns: minmax(230px, 1.2fr) repeat(3, minmax(145px, .7fr)) auto;
  align-items: end; gap: 10px; margin-bottom: 16px; padding: 14px; border-radius: 24px; background: var(--surface);
}
.filters.user-filters { grid-template-columns: minmax(190px, 1.2fr) repeat(4, minmax(128px, .75fr)) auto; }
.filters.compact { grid-template-columns: minmax(260px, 1fr) auto; }
.filter-field { min-width: 0; gap: 6px; }
.filter-field > span { padding-left: 3px; color: var(--muted); font-size: 11px; }
.filters input, .filters select, .filters button { min-height: 44px; }
.filters button { min-width: 76px; }

.list { display: grid; gap: 10px; }
.list-head, .user-row {
  display: grid; grid-template-columns: minmax(250px, 1.4fr) minmax(150px, .7fr) minmax(130px, .6fr) minmax(160px, .75fr) auto;
  gap: 14px; align-items: center;
}
.list-head { padding: 0 18px 6px; color: var(--muted); font-size: 11px; }
.user-row { min-height: 88px; padding: 14px 18px; border-radius: 22px; background: var(--surface); transition: background-color 160ms ease; }
.user-id, .code-value { font-family: "SF Mono", "SFMono-Regular", Consolas, monospace; }
.user-id { overflow-wrap: anywhere; font-size: 12px; }
.subline { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.note-preview { display: block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-text { font-size: 12px; }
.pill { display: inline-flex; min-height: 26px; align-items: center; justify-content: center; padding: 4px 10px; border-radius: 999px; background: #e5e9f0; color: #596170; font-size: 11px; font-weight: 740; white-space: nowrap; }
.pill.care_plus, .pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.king { background: #eee8dc; color: #705c2d; }
.pill.suspended, .pill.blocked { background: var(--danger-soft); color: var(--danger); }
.pill.deletion_pending, .pill.pending_confirmation, .pill.in_progress, .pill.pending { background: var(--warning-soft); color: var(--warning); }
.pill.completed, .pill.acknowledged, .pill.ready_to_finalize, .pill.success { background: var(--success-soft); color: var(--success); }
.cell-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 4px 0; color: var(--muted); font-size: 13px; }
.empty { padding: 54px 24px; border-radius: 26px; background: var(--surface); text-align: center; color: var(--muted); }
.empty-mark { display: grid; width: 42px; height: 42px; place-items: center; margin: 0 auto 14px; border-radius: 50%; background: var(--soft); color: var(--muted-strong); font-size: 20px; }

.code-row, .service-row { display: grid; gap: 16px; align-items: center; padding: 18px 20px; border-radius: 24px; }
.code-row { grid-template-columns: minmax(230px, 1fr) 110px 140px 170px auto; background: var(--surface); }
.service-row { grid-template-columns: minmax(210px, 1fr) minmax(190px, 1fr) 100px 150px auto; background: var(--row); }
.credential-list { grid-column: 1 / -1; display: grid; gap: 8px; padding-top: 4px; }
.credential-row {
  display: grid; grid-template-columns: minmax(150px, .8fr) minmax(170px, 1fr) minmax(170px, 1fr) 100px auto;
  align-items: center; gap: 12px; padding: 13px 15px; border-radius: 17px; background: var(--surface); color: var(--muted); font-size: 12px;
}
.code-value { overflow-wrap: anywhere; font-weight: 700; letter-spacing: .025em; }
.callout { padding: 17px 19px; border-radius: 20px; background: var(--accent-soft); color: #31548f; font-size: 13px; line-height: 1.65; }
.callout.warning { background: var(--warning-soft); color: #775615; }
.dialog-note { margin: 0; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 1.65; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-cell { min-width: 0; padding: 15px; border-radius: 17px; background: var(--soft); }
.detail-cell .value { margin-top: 5px; overflow-wrap: anywhere; font-weight: 650; line-height: 1.45; }
.event-list { display: grid; gap: 8px; max-height: 300px; overflow: auto; }
.event-item { padding: 14px; border-radius: 16px; background: var(--soft); font-size: 13px; }
.progress-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress-item > :first-child { min-width: 0; }
.dialog-inline-action { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 26px 0 12px; }
.section-title h3 { margin: 0; }
.button-cluster { display: flex; flex-wrap: wrap; gap: 8px; }
.group-create-action { margin-top: 0; }
.group-list { display: grid; gap: 8px; }
.group-row { display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border-radius: 18px; background: var(--soft); }
.group-row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 14px; border-radius: 16px; background: var(--soft); color: var(--muted-strong); line-height: 1.5; }
.check input { width: 18px; min-width: 18px; height: 18px; min-height: 18px; margin: 1px 0 0; padding: 0; border-radius: 5px; accent-color: var(--black); }

dialog {
  width: min(700px, calc(100% - 28px)); max-height: none; margin: auto; padding: 0; overflow: visible;
  border: 0; border-radius: 34px; background: transparent; color: var(--ink);
}
dialog[open] { animation: dialog-in 180ms ease-out; }
dialog::backdrop { background: rgba(9, 9, 9, .38); }
.dialog-card {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); padding: 28px; overflow: hidden;
  border-radius: inherit; background: var(--surface);
}
.dialog-head { display: flex; justify-content: space-between; gap: 20px; }
.dialog-head .eyebrow { margin-top: 0; }
.dialog-head h2 { margin-bottom: 0; }
.icon-button { width: 44px; min-width: 44px; height: 44px; min-height: 44px; flex: none; padding: 0; border-radius: 50%; }
.close-icon { position: relative; display: block; width: 18px; height: 18px; margin: auto; }
.close-icon::before, .close-icon::after {
  content: ""; position: absolute; top: 8px; left: 2px; width: 14px; height: 2px;
  border-radius: 999px; background: currentColor; transform: rotate(45deg);
}
.close-icon::after { transform: rotate(-45deg); }
.dialog-body {
  display: grid; gap: 16px; margin: 18px -6px 0; padding: 6px;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.inline-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.compact-textarea { min-height: 96px; }
.secret-box { padding: 18px; border-radius: 18px; background: #15171b; color: #fff; font-family: "SF Mono", "SFMono-Regular", Consolas, monospace; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.6; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 50; display: grid; gap: 8px; width: min(380px, calc(100% - 44px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 15px 17px; border-radius: 18px; background: var(--black); color: #fff; font-size: 13px; }
.toast::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: #66d5a4; }
.toast.error { background: var(--danger); }
.toast.error::before { background: #fff; }
.loading { display: grid; min-height: 330px; place-items: center; color: var(--muted); }
.loading-state { display: grid; justify-items: center; gap: 13px; }
.loading-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--black); animation: breathe 800ms ease-in-out infinite alternate; }
.skeleton { animation: fade-in 180ms ease-out; }

@keyframes breathe { from { opacity: .35; transform: scale(.88); } to { opacity: 1; transform: scale(1); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (hover: hover) {
  button:hover { background: var(--soft-strong); }
  button.primary:hover, .logout-button:hover { background: #272727; }
  button.danger:hover { background: #f3dddd; }
  button.quiet:hover { background: var(--soft); }
  .nav-pills button:hover { color: var(--ink); }
  .nav-pills button.active:hover { background: var(--black); color: #fff; }
  .user-row:hover, .code-row:hover { background: var(--row); }
}

@media (max-width: 1080px) {
  .topbar { grid-template-columns: 1fr auto; }
  .nav-pills { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .filters, .filters.user-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters button { width: 100%; }
  .list-head { display: none; }
  .user-row { grid-template-columns: 1fr 1fr; }
  .row-actions { justify-content: flex-start; }
  .code-row, .service-row { grid-template-columns: 1fr 1fr; }
  .credential-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
  .session-shell, .login-shell { padding: 14px; }
  .login-card { width: calc(100vw - 28px); padding: 30px; border-radius: 30px; }
  .login-copy { margin-top: 38px; }
  .app-shell { width: min(100% - 28px, 1240px); }
  .topbar { gap: 12px; padding: 14px 0 10px; }
  .topbar-icon { width: 34px; height: 33px; }
  .brand-copy small, .owner-chip { display: none; }
  .logout-button { min-height: 44px; padding-inline: 14px; }
  .nav-pills { width: 100%; min-width: 0; overflow-x: auto; justify-self: stretch; }
  .nav-pills button { min-width: 76px; padding-inline: 12px; }
  .content { padding: 24px 0 56px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 18px; }
  .head-actions { width: 100%; justify-content: stretch; }
  .head-actions button { width: 100%; }
  .metric-grid, .plan-strip, .filters, .user-row, .code-row, .service-row, .details-grid, .inline-fields { grid-template-columns: 1fr; }
  .filters.compact { grid-template-columns: 1fr; }
  .metric { min-height: 132px; }
  .panel { padding: 18px; border-radius: 26px; }
  .credential-row { grid-template-columns: 1fr; }
  .pagination { align-items: flex-start; flex-direction: column; }
  dialog { width: calc(100% - 20px); }
  .dialog-card { max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); padding: 22px; }
  .dialog-actions > button { flex: 1; }
  .group-row { align-items: flex-start; flex-direction: column; }
  .toast-region { right: 14px; bottom: 14px; width: calc(100% - 28px); }
}

@media (max-height: 720px) {
  .dialog-card { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding-block: 20px; }
  .dialog-body { margin-top: 12px; }
  .dialog-actions { margin-top: 16px; }
}

@media (max-width: 390px) {
  .login-card { padding: 26px; }
  .brand-copy strong { font-size: 15px; }
  .nav-pills button { min-width: 72px; font-size: 12px; }
  .dialog-actions { flex-direction: column-reverse; }
}

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