:root {
  color-scheme: light;
  --bg: #eef3f5;
  --surface: #ffffff;
  --surface-soft: #eef2f4;
  --surface-strong: #f8fafb;
  --line: #d9e0e5;
  --line-strong: #bec9d1;
  --text: #18222c;
  --muted: #64717d;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d7f1ee;
  --danger: #b42318;
  --danger-soft: #fde8e5;
  --warn: #946200;
  --warn-soft: #fff1cf;
  --ok: #177245;
  --ok-soft: #dff5e9;
  --queued: #315f9f;
  --queued-soft: #e1ecfb;
  --shadow: 0 16px 34px rgba(24, 34, 44, 0.08);
  --shadow-soft: 0 8px 20px rgba(24, 34, 44, 0.06);
  --topbar-height: 76px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: var(--topbar-height);
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(24, 34, 44, 0.06);
}

.header-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-left: auto;
}

.header-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.header-stats strong {
  color: var(--text);
  font-size: 16px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.3;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 22px;
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
  padding: 22px 28px 28px;
}

.sidebar,
.content {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overscroll-behavior: contain;
  padding-right: 10px;
  scrollbar-width: thin;
  scrollbar-color: #6f8796 rgba(210, 220, 226, 0.75);
}

.sidebar {
  overflow-y: auto;
}

.content {
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar,
.content::-webkit-scrollbar {
  width: 10px;
}

.sidebar::-webkit-scrollbar-track,
.content::-webkit-scrollbar-track {
  background: rgba(210, 220, 226, 0.75);
  border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb,
.content::-webkit-scrollbar-thumb {
  background: #6f8796;
  border: 2px solid rgba(210, 220, 226, 0.75);
  border-radius: 999px;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 16px;
}

.content {
  display: grid;
  align-content: start;
  gap: 16px;
  overflow-x: hidden;
}

.summary-grid,
.rule-strip,
.board-section,
.timeline-shell,
.table-wrap {
  min-width: 0;
  max-width: 100%;
}

.account-panel,
.panel,
.rule-strip,
.board-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-panel,
.panel {
  padding: 18px;
}

.account-panel,
.panel {
  border-top: 3px solid var(--accent);
}

.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.current-user strong,
.current-user span {
  display: block;
}

.current-user span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.login-grid,
.password-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.account-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.account-hint.error {
  color: var(--danger);
}

.password-tools,
.admin-tools {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.admin-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 900;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.admin-form .secondary-button {
  grid-column: 1 / -1;
}

.account-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.account-row {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.account-row span,
.account-row small {
  display: block;
}

.account-row small {
  margin-top: 2px;
  color: var(--muted);
}

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

.account-row strong {
  color: var(--accent-dark);
}

.micro-button {
  min-height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
  font-size: 11px;
  font-weight: 900;
}

.micro-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.panel-heading,
.section-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.schedule-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.field-group {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 40px;
  padding: 0 11px;
}

input[type="datetime-local"] {
  padding-right: 8px;
  font-size: 13px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 10px 11px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--accent);
}

.check-row label {
  display: block;
  color: var(--text);
  font-weight: 700;
}

.form-message {
  display: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.form-message.show {
  display: block;
}

.form-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-message.info {
  background: var(--queued-soft);
  color: var(--queued);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  gap: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.primary-button:disabled {
  background: #6fa59e;
}

.secondary-button:disabled {
  background: var(--surface-soft);
  color: var(--muted);
}

.rule-strip {
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 16px 20px;
  border-left: 6px solid var(--warn);
  background: linear-gradient(90deg, #fff7df, #ffffff 46%);
  box-shadow: 0 16px 34px rgba(148, 98, 0, 0.12);
}

.rule-strip-heading {
  display: grid;
  gap: 8px;
}

.rule-strip .eyebrow {
  margin-bottom: 2px;
  color: var(--warn);
}

.rule-strip ol {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-strip li {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid #f1cd7a;
  border-radius: 8px;
  background: #fffaf0;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
}

.rule-strip li::before {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(148, 98, 0, 0.12);
  flex: 0 0 auto;
}

.rule-manage-button {
  width: fit-content;
  border-color: #f1cd7a;
  background: #fffaf0;
}

.rule-editor {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid #f1cd7a;
}

.rule-editor-list {
  display: grid;
  gap: 8px;
}

.rule-editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #f1cd7a;
  border-radius: 8px;
  background: #fffdf6;
}

.rule-editor-row span {
  font-size: 13px;
  font-weight: 800;
}

.rule-editor-actions {
  display: flex;
  gap: 6px;
}

.rule-editor-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.gpu-card {
  min-height: 164px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.gpu-card.free {
  border-left-color: var(--ok);
}

.gpu-card.active {
  border-left-color: var(--danger);
}

.gpu-card.queued {
  border-left-color: var(--queued);
}

.gpu-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.gpu-card-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.gpu-primary {
  min-height: 38px;
  margin-top: 14px;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.35;
}

.gpu-metrics {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.gpu-metrics div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.gpu-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.gpu-metrics strong {
  text-align: right;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
}

.load-meter {
  height: 8px;
  overflow: hidden;
  margin-top: 14px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.load-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.gpu-card.active .load-meter span {
  background: var(--danger);
}

.gpu-card.queued .load-meter span {
  background: var(--queued);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.free,
.status-pill.done {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.active {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.queued {
  background: var(--queued-soft);
  color: var(--queued);
}

.status-pill.neutral {
  background: var(--surface-soft);
  color: var(--muted);
}

.status-pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.board-section {
  overflow: visible;
}

.section-toolbar {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.section-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.segmented {
  display: inline-flex;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segment {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.search-box {
  position: relative;
  display: block;
  width: min(260px, 100%);
}

.search-box span {
  position: absolute;
  top: 9px;
  left: 12px;
  color: var(--muted);
  font-weight: 900;
}

.search-box input {
  padding-left: 34px;
}

.timeline-shell {
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.timeline-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 0;
}

.timeline-title {
  font-size: 13px;
  font-weight: 900;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.active-dot {
  background: var(--danger);
}

.queued-dot {
  background: var(--queued);
}

.legend-line {
  width: 14px;
  height: 2px;
  background: var(--accent);
}

.timeline {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.timeline-heading {
  display: grid;
  grid-template-columns: 72px repeat(7, minmax(58px, 1fr));
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.timeline-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.timeline-label {
  font-size: 13px;
  font-weight: 900;
}

.timeline-track {
  position: relative;
  height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(to right, transparent calc(100% / 7 - 1px), var(--line) calc(100% / 7)) 0 0 / calc(100% / 7) 100%,
    linear-gradient(180deg, #fff, #f7fafb);
}

.timeline-bar {
  position: absolute;
  top: 6px;
  bottom: 6px;
  min-width: 3px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--queued);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 26px;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 7px;
}

.timeline-bar.active {
  background: var(--danger);
}

.timeline-bar.queued {
  background: var(--queued);
}

.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  width: 2px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.14);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  line-height: 1.45;
}

tbody tr:hover {
  background: #fbfcfd;
}

.gpu-cell {
  font-weight: 900;
}

.muted {
  color: var(--muted);
}

td .muted {
  font-size: 12px;
}

.purpose-cell {
  max-width: 290px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 132px;
}

.small-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.small-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.small-button.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.empty-state {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  body,
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar,
  .content {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rule-strip {
    grid-template-columns: 1fr;
  }

  .rule-strip ol {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rule-editor-form,
  .rule-editor-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 16px;
  }

  .header-stats {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }

  h1 {
    font-size: 20px;
  }

  .workspace {
    padding: 14px;
  }

  .two-col,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .rule-strip ol {
    grid-template-columns: 1fr;
  }

  .section-toolbar {
    display: grid;
  }

  .timeline-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-controls,
  .search-box {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
    padding: 0 6px;
  }

  .timeline-heading {
    grid-template-columns: 52px repeat(7, minmax(42px, 1fr));
    font-size: 11px;
  }

  .timeline-row {
    grid-template-columns: 52px minmax(0, 1fr);
  }
}
