:root {
  color-scheme: light;
  font-family: Inter, "SF Pro Display", "Segoe UI Variable", "Segoe UI", sans-serif;
  font-synthesis: none;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-alt: #f8f8fa;
  --graphite: #1d1d1f;
  --graphite-hover: #2c2c2e;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --muted: #8e8e93;
  --border: #d2d2d7;
  --border-soft: #e5e5ea;
  --accent: #e30613;
  --accent-hover: #c7000c;
  --blue: #0878d1;
  --success: #087f5b;
  --warning: #b05a00;
  --danger: #c91827;
  --shadow: 0 14px 40px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { border: 0; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid color-mix(in srgb, var(--blue) 70%, white); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .44; }
h1, h2, h3, h4, p { margin: 0; }
svg { width: 19px; height: 19px; stroke-width: 1.8; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }
.icon-button:hover { background: #ededf0; }
.icon-button.small { width: 30px; height: 30px; }
.icon-button.small svg { width: 16px; height: 16px; }
.primary-button, .secondary-button, .danger-button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.primary-button { background: var(--graphite); color: white; }
.primary-button:hover { background: #343437; }
.primary-button.compact, .secondary-button.compact, .danger-button.compact { min-height: 36px; padding: 7px 13px; }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.secondary-button:hover { background: #ededf0; }
.danger-button { background: var(--danger); color: white; }
.danger-button:hover { background: #aa1020; }

label { display: grid; gap: 7px; color: var(--secondary); font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: 8px 11px; }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #a9a9af; }

.login-view { min-height: 100%; position: relative; display: grid; place-items: center; padding: 32px; overflow: auto; }
.language-corner { position: fixed; top: 22px; right: 24px; }
.login-panel { width: min(408px, 100%); display: grid; gap: 20px; padding: 24px 0 48px; }
.login-logo { width: 76px; height: 76px; object-fit: contain; }
.login-heading { display: grid; gap: 7px; margin-bottom: 3px; }
.login-heading h1 { font-size: 34px; line-height: 1.12; font-weight: 680; }
.login-heading p { color: var(--secondary); line-height: 1.5; }
.login-form { display: grid; gap: 15px; }
.form-error { color: var(--danger); font-size: 13px; line-height: 1.45; }
.button-spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-view { height: 100%; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: 48px; display: grid; grid-template-rows: 1fr auto; padding: 0 3px; background: var(--graphite); color: white; overflow: hidden; transition: width .18s ease; box-shadow: 1px 0 rgba(255,255,255,.08); }
.sidebar:hover, .sidebar:focus-within { width: 224px; box-shadow: var(--shadow); }
.sidebar-brand { width: 218px; height: 48px; display: grid; grid-template-columns: 42px 160px; align-items: center; gap: 10px; padding: 0 5px; white-space: nowrap; overflow: hidden; }
.sidebar-brand img { width: 32px; height: 32px; justify-self: center; object-fit: contain; }
.sidebar-brand span { font-size: 15px; font-weight: 650; }
.sidebar-nav { display: grid; align-content: start; gap: 4px; padding-top: 72px; }
.sidebar-footer { display: grid; gap: 4px; padding-bottom: 0; }
.sidebar-item { width: 218px; height: 46px; display: grid; grid-template-columns: 42px 160px; align-items: center; gap: 10px; padding: 0; border-radius: 4px; background: transparent; color: #f5f5f7; text-align: left; white-space: nowrap; cursor: pointer; }
.sidebar-item:hover { background: var(--graphite-hover); }
.sidebar-item.active { background: #343437; }
.sidebar-item > svg { justify-self: center; }
.account-item { height: 54px; }
.account-item > span { display: grid; gap: 2px; min-width: 0; }
.group-item > span { display: grid; gap: 2px; min-width: 0; }
.account-item strong, .account-item small, .group-item strong, .group-item small { overflow: hidden; text-overflow: ellipsis; }
.account-item strong, .group-item strong { font-size: 13px; }
.account-item small, .group-item small { color: #a1a1a6; font-size: 11px; }

.workspace { height: 100%; margin-left: 48px; display: grid; grid-template-rows: 68px minmax(0,1fr) 34px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 28px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.9); backdrop-filter: blur(18px); }
.topbar h2 { font-size: 26px; font-weight: 670; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.global-status { max-width: 360px; color: var(--secondary); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 7px; border: 2px solid #b9b9be; border-top-color: var(--graphite); border-radius: 50%; animation: spin .7s linear infinite; }

.page { min-height: 0; }
.projects-page { display: grid; grid-template-columns: 300px minmax(0,1fr); }
.project-index { min-width: 0; border-right: 1px solid var(--border); background: var(--surface-alt); overflow: hidden; }
.section-toolbar, .panel-toolbar { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 12px; border-bottom: 1px solid var(--border-soft); }
.toolbar-buttons { display: flex; align-items: center; gap: 6px; }
.section-toolbar > div, .panel-toolbar > div:first-child { display: flex; align-items: baseline; gap: 8px; }
.section-toolbar h3, .panel-toolbar h4 { font-size: 16px; }
.section-toolbar span, .panel-toolbar p { color: var(--secondary); font-size: 12px; }
.project-list { height: calc(100% - 52px); overflow: auto; }
.project-row { width: 100%; display: grid; gap: 5px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); background: transparent; text-align: left; cursor: pointer; }
.project-row:hover { background: #ededf0; }
.project-row.active { background: var(--surface); box-shadow: inset 3px 0 var(--accent); }
.project-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.project-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--secondary); font-size: 12px; }

.project-detail { min-width: 0; min-height: 0; background: var(--surface); }
.project-detail.empty { display: grid; place-items: center; }
.empty-state { display: grid; justify-items: center; gap: 12px; color: var(--muted); }
.empty-state svg { width: 34px; height: 34px; }
.empty-state h3 { font-size: 15px; font-weight: 600; }
#project-content { height: 100%; display: grid; grid-template-rows: auto 48px minmax(0,1fr); }
.project-header { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 28px; border-bottom: 1px solid var(--border-soft); }
.project-header > div { min-width: 0; display: grid; gap: 5px; }
.project-header h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 21px; }
.project-header p { max-width: 780px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--secondary); font-size: 13px; }
.tabs { display: flex; align-items: end; gap: 22px; padding: 0 22px; border-bottom: 1px solid var(--border); }
.tab { height: 48px; padding: 0 2px; border-bottom: 2px solid transparent; background: transparent; color: var(--secondary); cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 650; }
.tab-panel { min-height: 0; display: none; overflow: auto; }
.tab-panel.active { display: block; }
.panel-toolbar { min-height: 72px; padding: 12px 22px; }
.panel-toolbar > div:first-child { display: grid; gap: 4px; }
.command-row { display: flex; align-items: center; gap: 8px; }

.transfer-strip { display: grid; grid-template-columns: minmax(180px,1fr) minmax(180px,340px) 32px; align-items: center; gap: 16px; padding: 10px 22px; border-bottom: 1px solid var(--border-soft); background: #f8f8fa; }
.transfer-strip > div { display: grid; gap: 2px; min-width: 0; }
.transfer-strip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.transfer-strip strong { color: var(--secondary); font-size: 11px; font-weight: 500; }
progress { width: 100%; height: 5px; accent-color: var(--accent); }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { height: 48px; padding: 8px 12px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: middle; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface-alt); color: var(--secondary); font-weight: 650; }
th:first-child, td:first-child { padding-left: 22px; width: 31%; }
th:last-child, td:last-child { width: 50px; padding-right: 16px; text-align: right; }
td { color: var(--secondary); }
td strong { color: var(--text); font-weight: 600; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; color: var(--secondary); font-size: 11px; font-weight: 650; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-pill.ready::before, .status-pill.succeeded::before { background: var(--success); }
.status-pill.running::before, .status-pill.pending::before { background: var(--blue); }
.status-pill.failed::before, .status-pill.cancelled::before { background: var(--danger); }
.row-action { border: 0; background: transparent; color: var(--secondary); cursor: pointer; }
.row-action:hover { color: var(--danger); }

.training-layout { min-height: 100%; display: grid; grid-template-columns: 300px minmax(0,1fr); }
.training-content { min-width: 0; overflow: auto; }
.parameter-panel { max-width: 760px; display: grid; align-content: start; gap: 16px; padding: 24px 28px; background: var(--surface); }
.parameter-panel > div { display: grid; gap: 4px; margin-bottom: 2px; }
.parameter-panel h4 { font-size: 16px; }
.parameter-panel p { color: var(--secondary); font-size: 12px; line-height: 1.45; }
.parameter-grid { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px !important; }
.training-options { display: flex !important; align-items: center; gap: 24px !important; }
.parameter-panel > .primary-button { justify-self: start; }
.toggle-row { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 500; }
.toggle-row input { width: 17px; min-height: 17px; accent-color: var(--accent); }
.job-area { min-width: 0; display: grid; grid-template-rows: 52px minmax(150px,1fr); border-right: 1px solid var(--border-soft); background: var(--surface-alt); }
.job-list { overflow: auto; }
.job-row { width: 100%; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); background: transparent; text-align: left; cursor: pointer; }
.job-row:hover, .job-row.active { background: var(--surface-alt); }
.job-row strong { display: block; margin-bottom: 4px; font-size: 13px; }
.job-row small { color: var(--secondary); }
.mini-progress { display: grid; grid-template-columns: 1fr 35px; align-items: center; gap: 7px; color: var(--secondary); font-size: 11px; }
.job-row .job-time, .job-row .mini-progress { display: none; }
.job-detail { max-width: 760px; padding: 20px 28px 36px; border-top: 1px solid var(--border); background: var(--surface); overflow: visible; }
.job-detail-grid { display: grid; grid-template-columns: repeat(4,minmax(100px,1fr)); gap: 12px; }
.metric { display: grid; gap: 3px; }
.metric span { color: var(--secondary); font-size: 10px; text-transform: uppercase; }
.metric strong { font-size: 13px; }
.job-actions { display: flex; gap: 8px; margin-top: 14px; }

.viewer-panel.active { position: relative; display: block; overflow: hidden; background: #090a0c; }
.viewer-toolbar { position: absolute; z-index: 4; top: 14px; left: 14px; width: 330px; display: grid; gap: 8px; padding: 14px; border: 1px solid #48484a; border-radius: 4px; background: rgba(29,29,31,.94); color: white; }
.viewer-toolbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.viewer-toolbar select { width: 100%; min-height: 36px; border-color: #48484a; background: #2c2c2e; color: white; }
.viewer-toolbar .icon-button { border-color: #48484a; background: #2c2c2e; color: white; }
.viewer-toolbar .icon-button:hover { background: #3a3a3c; }
.viewer-command-row { display: flex; align-items: center; gap: 8px; }
.viewer-actions { position: absolute; z-index: 4; top: 14px; right: 14px; display: flex; gap: 6px; padding: 4px; border: 1px solid #48484a; border-radius: 4px; background: rgba(29,29,31,.94); }
.viewer-actions .icon-button { border-color: transparent; background: transparent; color: white; }
.viewer-actions .icon-button:hover { background: #3a3a3c; }
.viewer-panel:fullscreen { width: 100vw; height: 100vh; background: #090a0c; }
.viewer-panel.viewer-expanded { position: fixed; inset: 0; z-index: 120; width: 100vw; height: 100vh; display: block; background: #090a0c; }
.fps { color: #a1a1a6; font: 11px Consolas, monospace; }
.viewer-stage { position: absolute; inset: 0; overflow: hidden; }
.viewer-stage canvas { width: 100%; height: 100%; display: block; }
.viewer-empty { position: absolute; inset: 0; z-index: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: #a1a1a6; pointer-events: none; }
.viewer-empty img { width: 62px; height: 62px; opacity: .8; }
.viewer-empty p { font-size: 12px; }
.viewer-progress { position: absolute; left: 20%; right: 20%; bottom: 24px; z-index: 5; display: grid; gap: 7px; padding: 12px 14px; border: 1px solid #48484a; background: rgba(29,29,31,.9); color: white; box-shadow: var(--shadow); }
.viewer-progress span { font-size: 11px; }

.statusbar { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 14px; border-top: 1px solid var(--border); background: var(--surface-alt); }
.statusbar small { color: var(--secondary); font: 10px Consolas, monospace; }

.settings-page { overflow: auto; padding: 28px; }
.settings-section { max-width: 720px; display: grid; gap: 17px; padding: 22px 0; border-bottom: 1px solid var(--border); }
.settings-section header { display: grid; gap: 5px; }
.settings-section h3 { font-size: 18px; }
.settings-section p, .settings-section small { color: var(--secondary); }
.settings-section .primary-button { justify-self: start; }

.app-dialog { width: min(480px,calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.app-dialog::backdrop { background: rgba(0,0,0,.28); backdrop-filter: blur(3px); }
.app-dialog form { display: grid; gap: 16px; padding: 20px; }
.app-dialog header, .app-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.app-dialog footer { justify-content: flex-end; padding-top: 5px; }
.confirm-dialog p { color: var(--secondary); line-height: 1.5; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 11px 14px; border: 1px solid var(--border); border-left: 3px solid var(--graphite); border-radius: 5px; background: var(--surface); box-shadow: var(--shadow); font-size: 13px; }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 920px) {
  .projects-page { grid-template-columns: 220px minmax(0,1fr); }
  .training-layout { grid-template-columns: 220px minmax(0,1fr); }
  .parameter-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  html, body { overflow: auto; }
  .app-view { min-height: 100dvh; }
  .sidebar { inset: 0 0 auto; width: 100%; height: 58px; grid-template-columns: auto 1fr auto; grid-template-rows: 1fr; padding: 5px 8px; transition: none; }
  .sidebar:hover, .sidebar:focus-within { width: 100%; box-shadow: none; }
  .sidebar-brand { width: 44px; grid-template-columns: 42px; }
  .sidebar-brand span { display: none; }
  .sidebar-nav, .sidebar-footer { display: flex; align-items: center; justify-content: flex-end; padding: 0; }
  .sidebar-nav { justify-content: center; }
  .sidebar-item { width: 44px; grid-template-columns: 42px; overflow: hidden; }
  .sidebar-item > span { display: none; }
  .account-item { display: none; }
  .workspace { min-height: 100dvh; height: auto; margin-left: 0; padding-top: 58px; grid-template-rows: 62px auto 34px; }
  .topbar { position: sticky; top: 58px; z-index: 20; padding: 0 15px; }
  .topbar h2 { font-size: 20px; }
  .global-status { display: none; }
  .projects-page { min-height: calc(100dvh - 120px); grid-template-columns: 1fr; }
  .project-index { height: 210px; border-right: 0; border-bottom: 1px solid var(--border); }
  .project-detail { min-height: 620px; }
  .project-header { min-height: 76px; padding: 13px 15px; }
  .project-header h3 { font-size: 18px; }
  .tabs { gap: 18px; padding: 0 15px; overflow-x: auto; }
  .panel-toolbar { align-items: flex-start; padding: 12px 15px; }
  .command-row { flex-wrap: wrap; justify-content: flex-end; }
  .transfer-strip { grid-template-columns: 1fr 30px; }
  .transfer-strip progress { grid-column: 1 / -1; grid-row: 2; }
  .training-layout { grid-template-columns: 1fr; }
  .parameter-panel { padding: 20px 16px; border-bottom: 1px solid var(--border); }
  .training-options { align-items: flex-start; flex-direction: column; gap: 10px !important; }
  .job-area { min-height: 420px; }
  .job-row { padding: 11px 12px; gap: 8px; }
  .job-detail-grid { grid-template-columns: repeat(2,1fr); }
  .viewer-panel.active { min-height: 620px; }
  .viewer-toolbar { left: 10px; right: 10px; width: auto; }
  .viewer-actions { top: auto; right: 10px; bottom: 10px; }
  .viewer-progress { left: 15px; right: 15px; }
  .settings-page { padding: 20px 16px; }
  th:nth-child(2), td:nth-child(2), th:nth-child(4), td:nth-child(4) { display: none; }
  th:first-child, td:first-child { width: 48%; padding-left: 15px; }
}
