:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: #17211c;
  background: #f3f5f4;
  font-synthesis: none;
  --surface: #ffffff;
  --surface-subtle: #f7f9f8;
  --surface-hover: #f0f4f2;
  --text: #17211c;
  --muted: #66736c;
  --border: #dce4df;
  --border-strong: #c8d3cd;
  --primary: #16724a;
  --primary-hover: #0f5e3c;
  --primary-soft: #e9f5ef;
  --info: #2463d4;
  --warning: #b6610b;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(23, 33, 28, .08);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--surface-subtle);
  color: var(--text);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 24px; line-height: 1.3; letter-spacing: 0; }
h2 { margin: 0; font-size: 18px; line-height: 1.4; letter-spacing: 0; }
.muted { color: var(--muted); }

/* Shared brand */
.brand,
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.brand-logo.large {
  width: 52px;
  height: 52px;
}

.brand > div,
.login-brand > div { min-width: 0; }

.brand strong,
.brand span {
  display: block;
  letter-spacing: 0;
}

.brand strong { font-size: 15px; line-height: 1.25; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }

/* Login */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--surface-subtle);
}

.login-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand h1 { margin-bottom: 3px; font-size: 21px; }
.login-brand p { margin-bottom: 0; font-size: 13px; }
.login-panel form { display: grid; gap: 18px; margin-top: 30px; }

/* Controls */
label {
  display: grid;
  gap: 7px;
  color: #37423d;
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  font-weight: 400;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input::placeholder { color: #8a9690; }

input:hover,
select:hover { border-color: #aebdb5; }

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(36, 99, 212, .2);
  outline-offset: 2px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 114, 74, .12);
}

button {
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 0 14px;
  color: #26312c;
  background: var(--surface);
  font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

button:hover:not(:disabled) {
  border-color: #aebdb5;
  background: var(--surface-hover);
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.primary:hover:not(:disabled) {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.text-button {
  min-height: 32px;
  border: 0;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
}

.text-button:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-hover);
}

.icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
}

button.danger {
  border-color: #e5aaa5;
  color: var(--danger);
}

button.danger:hover:not(:disabled) {
  border-color: #d98f88;
  background: #fff1f0;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

.message {
  padding: 11px 13px;
  border: 1px solid #b8d8c7;
  border-radius: 5px;
  background: #edf8f2;
  color: #185c3b;
  font-size: 13px;
}

/* App shell */
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 max(24px, calc((100vw - 1380px) / 2 + 28px));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.account {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.account > span {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-tabs {
  position: sticky;
  z-index: 15;
  top: 64px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.view-tabs-inner {
  max-width: 1380px;
  height: 48px;
  display: flex;
  align-items: stretch;
  gap: 26px;
  margin: 0 auto;
  padding: 0 28px;
}

.view-tabs a {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.view-tabs a::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: transparent;
}

.view-tabs a:hover { color: var(--text); }
.view-tabs a.active { color: var(--primary); }
.view-tabs a.active::after { background: var(--primary); }

.global-message-wrap {
  max-width: 1380px;
  margin: 0 auto;
  padding: 16px 28px 0;
}

.page {
  max-width: 1380px;
  margin: 0 auto;
  padding: 28px;
}

.owner-view { min-height: calc(100vh - 112px); }
.narrow-page { max-width: 980px; }

.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-heading > div { min-width: 0; }
.page-heading p { margin-bottom: 0; font-size: 13px; }

/* Summary metrics */
.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 22px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.summary > div {
  min-width: 0;
  padding: 17px 20px;
  border-right: 1px solid var(--border);
}

.summary > div:last-child { border-right: 0; }

.summary span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.summary strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: 0;
}

#organization-expiry { font-size: 17px; }

/* Data tools and tables */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input { max-width: 360px; }

.task-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 140px 160px 156px 156px auto;
  align-items: end;
  gap: 10px;
  margin: 0 0 12px;
}

.task-filters label { gap: 5px; font-size: 12px; }
.task-filters button { height: 42px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #e7ece9;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: #58645e;
  background: var(--surface-subtle);
  font-size: 12px;
  font-weight: 700;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
td strong { font-weight: 650; }
td .muted { font-size: 11px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #7d8983;
}

.status.active::before,
.status.online::before,
.status.task-completed::before { background: #168653; }

.status.expired::before,
.status.suspended::before,
.status.task-queued::before,
.status.task-waiting_verification::before { background: var(--warning); }

.status.disabled::before,
.status.task-failed::before,
.status.task-download_failed::before,
.status.task-cancelled::before { background: var(--danger); }

.status.task-leased::before,
.status.task-generating::before,
.status.task-submitting::before,
.status.task-downloading::before,
.status.task-verification_resuming::before { background: var(--info); }

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.empty {
  padding: 54px 20px;
  text-align: center;
  color: #76817c;
  font-size: 13px;
}

.task-error {
  max-width: 280px;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--danger);
}

.task-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 16px; }
.task-pagination > span { margin-right: auto; }
#task-prev, #task-next { width: 40px; height: 36px; padding: 0; }
#task-list td:first-child { min-width: 160px; max-width: 320px; white-space: normal; overflow-wrap: anywhere; }
#task-load-error { overflow-wrap: anywhere; }

.profile-table th { width: 190px; }
.profile-table td { white-space: normal; }

/* Dialogs */
dialog {
  width: min(650px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(18, 30, 24, .22);
}

dialog::backdrop { background: rgba(19, 28, 24, .46); }
dialog form { padding: 24px; }

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.dialog-heading p { margin: 4px 0 0; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.one-column { grid-template-columns: 1fr; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@media (max-width: 960px) {
  .task-filters { grid-template-columns: 1fr 1fr 1fr; }
  .task-filters > :first-child { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .login-view { padding: 16px; background: var(--surface-subtle); }
  .login-panel { padding: 26px 22px; }
  .topbar { height: 60px; padding: 0 16px; }
  .brand-logo { width: 34px; height: 34px; }
  .brand span { display: none; }
  .account > span { max-width: 110px; }
  .view-tabs { top: 60px; overflow-x: auto; }
  .view-tabs-inner { width: max-content; min-width: 100%; height: 46px; gap: 22px; padding: 0 16px; }
  .global-message-wrap { padding: 12px 16px 0; }
  .page { padding: 22px 16px; }
  .page-heading { align-items: flex-start; margin-bottom: 18px; }
  .page-heading h1 { font-size: 21px; }
  .page-heading > button { flex: 0 0 auto; }
  .summary { grid-template-columns: 1fr; }
  .summary > div { padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .summary > div:last-child { border-bottom: 0; }
  .summary strong { font-size: 19px; }
  .toolbar { align-items: stretch; }
  .toolbar input { max-width: none; }
  .task-filters { grid-template-columns: 1fr 1fr; }
  .task-filters > :first-child { grid-column: 1 / -1; }
  .task-filters label { min-width: 0; }
  .task-filters button { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .profile-table th { width: 132px; }
}

@media (max-width: 430px) {
  .login-brand { align-items: flex-start; }
  .account { gap: 2px; }
  .page-heading { flex-direction: column; }
  .page-heading > button { width: 100%; }
  .toolbar { display: grid; grid-template-columns: 1fr auto; }
  .task-filters { grid-template-columns: 1fr; }
  .task-filters > :first-child,
  .task-filters button { grid-column: auto; }
  dialog form { padding: 20px; }
}

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

/* Platform admin: scoped extension, shared owner/member surfaces stay unchanged. */
#organizations-view .actions { flex-wrap: wrap; min-width: 210px; max-width: 230px; }
#organization-view { font-variant-numeric: tabular-nums; }
#organization-view .detail-heading { margin-top: 20px; }
#organization-title, #organization-subtitle, #edit-name { overflow-wrap: anywhere; }
#organization-view .actions { flex-wrap: wrap; }
#organization-view .error { margin: 12px 0; overflow-wrap: anywhere; }
.quota-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 20px 0 12px; }
.quota-grid dt { font-size: 12px; color: var(--muted); }
.quota-grid dd { margin: 8px 0 0; font-size: 18px; font-weight: 600; }
.form-note { margin: 16px 0 0; font-size: 13px; line-height: 1.6; }
.resource-details { margin: 24px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 16px 0; }
.resource-details summary { cursor: pointer; font-weight: 600; }
.resource-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 24px; margin-top: 20px; }
.resource-columns h2 { margin-bottom: 10px; }
.resource-columns p { font-size: 13px; }
.admin-jobs { margin-top: 28px; }
.admin-jobs > h2 { margin-bottom: 8px; }
.admin-jobs > p { font-size: 13px; line-height: 1.6; }
.admin-job-filters { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(120px, 1fr)); gap: 12px; align-items: end; margin: 20px 0 16px; }
.admin-job-filters label { min-width: 0; font-size: 12px; }
.admin-job-filters .actions { align-self: end; min-height: 42px; }
.admin-job-filters .actions button { min-height: 42px; font-size: 13px; }
#admin-job-list td:first-child { min-width: 180px; max-width: 300px; white-space: normal; overflow-wrap: anywhere; }
#organization-view .table-wrap { max-width: 100%; }
#organization-view .empty { color: var(--muted); }
#organization-view :focus-visible, #edit-dialog :focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
#organization-view input, #edit-dialog input { caret-color: var(--primary); }
#organization-view input::placeholder { color: var(--muted); opacity: 1; }
#organization-view ::selection, #edit-dialog ::selection { background: var(--primary-soft); color: var(--text); }
#edit-error { margin-top: 16px; }
@media (max-width: 960px) {
  .admin-job-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .resource-columns { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .quota-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #organization-view .page-heading { flex-wrap: wrap; }
}
@media (max-width: 430px) {
  .admin-job-filters { grid-template-columns: minmax(0, 1fr); }
  #organization-view .page-heading > .actions { width: 100%; }
}
