:root {
  --ink: #15201b;
  --muted: #637069;
  --surface: #ffffff;
  --surface-subtle: #f4f6f3;
  --canvas: #ecefea;
  --line: #d8ded9;
  --line-strong: #b7c1ba;
  --brand: #176b4f;
  --brand-hover: #10573f;
  --brand-soft: #ddefe6;
  --danger: #a83333;
  --danger-soft: #f8e4e2;
  --warning: #8b5c0a;
  --warning-soft: #f8edcf;
  --info: #27657b;
  --info-soft: #dcecf1;
  --focus: #0b6fc2;
  --shadow: 0 10px 28px rgb(22 43 31 / 7%);
  --radius: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: var(--canvas); line-height: 1.5; }
button, input { font: inherit; }
a { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent); outline-offset: 3px; }

.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.page-shell { padding-block: 42px 72px; }
.skip-link { position: fixed; z-index: 100; top: 10px; left: 10px; transform: translateY(-160%); background: var(--ink); color: white; padding: 10px 14px; }
.skip-link:focus { transform: translateY(0); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-header { position: sticky; z-index: 20; top: 0; background: rgb(255 255 255 / 94%); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.header-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); font-weight: 720; text-decoration: none; letter-spacing: -.015em; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #1e795d; background: var(--brand); color: white; border-radius: 8px; font-size: 12px; letter-spacing: -.04em; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav > a, .nav .button-quiet { display: inline-flex; min-height: 42px; align-items: center; padding: 8px 12px; border: 0; color: var(--muted); background: transparent; border-radius: 7px; font-weight: 600; text-decoration: none; cursor: pointer; }
.nav > a:hover, .nav .button-quiet:hover { background: var(--surface-subtle); color: var(--ink); }
.nav > a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }
.nav form { display: contents; }

h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 800px; margin-bottom: 10px; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1.04; letter-spacing: -.045em; }
h2 { font-size: 1.22rem; line-height: 1.2; letter-spacing: -.02em; }
h3 { font-size: 1.05rem; line-height: 1.25; }
.page-heading { margin-bottom: 34px; }
.page-heading > p, .login-intro > p { max-width: 690px; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; }
.heading-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.heading-actions > div:first-child { min-width: 0; }
.eyebrow { display: block; margin-bottom: 9px; color: var(--brand); font-size: .78rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.section-title { margin-bottom: 16px; }
.section-block { margin-top: 40px; }
.section-heading { min-height: 30px; margin-bottom: 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; }
.muted { color: var(--muted); }
.break-word { overflow-wrap: anywhere; }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; padding: 9px 15px; border-radius: 7px; font-weight: 680; line-height: 1.15; text-decoration: none; cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--brand); color: white; border-color: var(--brand); }
.button-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.button-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.button-secondary:hover { background: var(--surface-subtle); border-color: #89968e; }
.button-danger { background: var(--surface); border-color: #d7a4a1; color: var(--danger); }
.button-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.button-full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .48; transform: none; }
.text-link, .file-link { color: var(--brand); font-weight: 650; text-underline-offset: 3px; }
.text-link:hover, .file-link:hover { color: var(--brand-hover); }
.action-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.inset-panel { padding: 22px; box-shadow: none; }
.panel-heading { margin-bottom: 22px; }
.panel-heading h2 { margin-bottom: 7px; }
.panel-heading p { margin: 0; color: var(--muted); }
.notice { margin-bottom: 20px; padding: 12px 14px; border: 1px solid; border-radius: 7px; }
.notice-success { background: var(--brand-soft); border-color: #b3d9c7; color: #0f5b40; }
.notice-error { background: var(--danger-soft); border-color: #e3b8b4; color: #822727; }
.notice-info { background: var(--info-soft); border-color: #b6d6df; color: #184f63; }

.login-layout { min-height: calc(100vh - 120px); display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 410px); align-items: center; gap: clamp(50px, 9vw, 130px); }
.login-intro h1 { max-width: 720px; }
.login-panel { padding: 30px; }
.field { display: grid; gap: 7px; margin-bottom: 17px; color: var(--ink); font-size: .91rem; font-weight: 650; }
.field input { width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: white; color: var(--ink); }
.field input:hover { border-color: #86958c; }
.field input:focus { border-color: var(--focus); outline: 3px solid rgb(11 111 194 / 17%); }
.field input:disabled { cursor: not-allowed; background: var(--surface-subtle); color: var(--muted); }
.field-help { max-width: 700px; margin: -9px 0 18px; color: var(--muted); font-size: .82rem; }

.course-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.course-card { display: grid; grid-template-columns: 48px 1fr; gap: 16px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 18px rgb(22 43 31 / 4%); }
.course-icon { display: grid; place-items: center; width: 48px; height: 48px; background: #e3ebe6; color: var(--brand); border: 1px solid #c7d5cc; border-radius: 8px; font-weight: 780; font-size: 1.2rem; }
.course-body { min-width: 0; }
.course-heading { display: flex; justify-content: space-between; gap: 12px; }
.course-heading h3 { margin: 1px 0 3px; overflow-wrap: anywhere; }
.course-heading p { margin: 0; color: var(--muted); font-size: .88rem; }
.course-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 21px 0; padding-top: 15px; border-top: 1px solid var(--line); }
.course-meta div, .connection-meta div { min-width: 0; }
.course-meta dt, .connection-meta dt { color: var(--muted); font-size: .76rem; }
.course-meta dd, .connection-meta dd { margin: 3px 0 0; overflow-wrap: anywhere; font-size: .88rem; font-weight: 620; }
.course-actions { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }
.empty-state { padding: 60px 24px; text-align: center; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--muted); }
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 18px; border: 1px solid var(--line); border-radius: 50%; color: var(--brand); font-size: 1.4rem; }

.status { width: fit-content; max-width: 210px; display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-subtle); color: var(--muted); font-size: .76rem; font-weight: 700; line-height: 1.15; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
.status-active, .status-queued, .status-scanning, .status-planning, .status-transferring, .status-cancelling, .status-downloading, .status-uploading, .status-retry_wait { background: var(--info-soft); border-color: #b6d6df; color: var(--info); }
.status-completed, .status-uploaded, .status-skipped_duplicate, .status-connected { background: var(--brand-soft); border-color: #b3d9c7; color: #115b42; }
.status-completed_with_errors, .status-unassigned { background: var(--warning-soft); border-color: #e6d29e; color: var(--warning); }
.status-failed_system, .status-failed, .status-cancelled, .status-unavailable { background: var(--danger-soft); border-color: #e3b8b4; color: var(--danger); }
.status-demo { background: var(--warning-soft); border-color: #e6d29e; color: var(--warning); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--surface-subtle); color: var(--muted); font-size: .74rem; font-weight: 750; letter-spacing: .035em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbf9; }
.file-name, .file-link { max-width: 300px; display: block; overflow-wrap: anywhere; }
.error-detail { max-width: 360px; display: block; margin-top: 5px; color: var(--danger); }
.assign-form { min-width: 250px; display: flex; align-items: center; gap: 7px; }
.assign-form select { width: min(240px, 100%); min-height: 40px; border: 1px solid var(--line-strong); border-radius: 6px; background: white; padding: 7px 9px; }

.breadcrumbs { display: flex; gap: 8px; margin-bottom: 24px; color: var(--muted); font-size: .86rem; }
.breadcrumbs a { color: var(--brand); }
.run-summary { padding: 24px; }
.run-status-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.run-status-row h2 { margin-bottom: 5px; }
.run-status-row p { margin-bottom: 0; color: var(--muted); }
.progress-block { margin-top: 25px; }
.progress-label { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 8px; font-size: .88rem; }
.progress-label strong { font-size: .84rem; }
.progress-track { height: 9px; overflow: hidden; background: #dfe5e0; border-radius: 99px; }
.progress-track span { height: 100%; display: block; background: var(--brand); border-radius: inherit; transition: width .35s ease; }
.transfer-metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 22px 0 0; }
.transfer-metric-grid div { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.transfer-metric-grid dt { color: var(--muted); font-size: .75rem; }
.transfer-metric-grid dd { margin: 4px 0 1px; overflow-wrap: anywhere; font-size: 1.15rem; font-weight: 730; }
.transfer-metric-grid small { display: block; color: var(--muted); font-size: .72rem; }
.metric-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; margin: 28px 0 0; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.metric-grid div { padding: 15px; background: var(--surface-subtle); }
.metric-grid dt { color: var(--muted); font-size: .75rem; }
.metric-grid dd { margin: 4px 0 0; font-size: 1.28rem; font-weight: 730; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(290px, .7fr); align-items: start; gap: 25px; }
.event-list { max-height: 560px; overflow: auto; margin: 0; padding: 5px 0 5px 5px; list-style: none; }
.event { position: relative; display: grid; grid-template-columns: 12px 1fr; gap: 10px; padding-bottom: 18px; }
.event::before { position: absolute; left: 5px; top: 10px; bottom: -2px; width: 1px; background: var(--line); content: ""; }
.event:last-child::before { display: none; }
.event-marker { position: relative; z-index: 1; width: 11px; height: 11px; margin-top: 5px; border: 2px solid var(--surface); border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.event-warning .event-marker { background: var(--warning); box-shadow: 0 0 0 1px var(--warning); }
.event-error .event-marker { background: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.event p { margin: 0 0 3px; font-size: .88rem; }
.event time { color: var(--muted); font-size: .72rem; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.connection-card { padding: 22px; box-shadow: 0 5px 18px rgb(22 43 31 / 4%); }
.telegram-connection { grid-column: 1 / -1; }
.connection-heading { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 13px; }
.connection-heading h2 { margin: 0 0 3px; }
.connection-heading p { margin: 0; color: var(--muted); font-size: .82rem; }
.connection-icon { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid; border-radius: 8px; font-size: .76rem; font-weight: 800; }
.telegram-icon { color: #286b87; background: #e2eff4; border-color: #bdd7e1; }
.storage-icon { color: #765015; background: #f6ecd6; border-color: #e3d1a6; }
.database-icon { color: #5b4c82; background: #ece7f5; border-color: #d3c8e8; }
.connection-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 21px 0 0; padding-top: 17px; border-top: 1px solid var(--line); }
.telegram-auth { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.auth-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.auth-intro .eyebrow { margin-bottom: 5px; }
.auth-intro h3 { margin-bottom: 5px; font-size: 1.18rem; }
.auth-intro p { max-width: 680px; margin: 0; color: var(--muted); }
.auth-expiry { flex: none; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .76rem; font-weight: 680; }
.auth-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 22px 0 16px; padding: 0; list-style: none; }
.auth-steps li { min-width: 0; display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface-subtle); }
.auth-steps li.is-current { border-color: #8ab9a6; color: var(--ink); background: var(--brand-soft); }
.auth-steps li.is-complete { border-color: #b3d9c7; color: var(--brand); background: #eef8f3; }
.step-number { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: .78rem; font-weight: 760; }
.auth-steps strong, .auth-steps small { display: block; overflow-wrap: anywhere; }
.auth-steps strong { font-size: .86rem; }
.auth-steps small { margin-top: 1px; color: var(--muted); font-size: .7rem; }
.auth-panel { padding: 20px; border: 1px solid var(--line); border-radius: 9px; background: #fafbf9; }
.compact-notice { margin-bottom: 16px; font-size: .88rem; }
.compact-notice code { overflow-wrap: anywhere; font-size: .82em; }
.auth-form { max-width: 660px; }
.auth-form .button { min-width: 190px; }
.auth-stage-heading { max-width: 660px; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.auth-stage-heading strong, .stage-label { display: block; }
.auth-stage-heading strong { margin-top: 2px; letter-spacing: .03em; }
.stage-label, .attempts { color: var(--muted); font-size: .78rem; }
.attempts { flex: none; }
#telegram-code { max-width: 220px; letter-spacing: .18em; font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.auth-cancel-form { margin-top: 12px; }
.inline-quiet { min-height: 36px; padding: 6px 0; border: 0; color: var(--muted); background: transparent; }
.inline-quiet:hover { color: var(--danger); }
.auth-safety { margin-top: 18px; padding: 18px 20px; border-left: 3px solid #d3b56a; background: #fbf7ec; }
.auth-safety h3 { margin-bottom: 10px; }
.auth-safety ul { margin: 0; padding-left: 20px; color: #514a39; }
.auth-safety p { margin: 12px 0 0; color: var(--muted); font-size: .84rem; }
.connected-summary { display: grid; gap: 3px; margin-top: 22px; padding: 15px 17px; border: 1px solid #b3d9c7; border-radius: 8px; background: var(--brand-soft); color: #115b42; }
.connected-summary span { font-size: .86rem; }
.safety-note { padding: 23px; box-shadow: none; }
.safety-note h2 { margin-bottom: 12px; }
.safety-note ul { margin: 0; padding-left: 20px; color: var(--muted); }

@media (max-width: 880px) {
  .course-grid, .settings-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .login-layout { grid-template-columns: 1fr; align-content: center; gap: 34px; }
  .login-intro { text-align: center; }
  .login-intro p { margin-inline: auto; }
  .login-panel { width: min(430px, 100%); margin-inline: auto; }
}

@media (max-width: 640px) {
  .shell { width: min(100% - 24px, 1180px); }
  .page-shell { padding-block: 28px 50px; }
  .header-inner { min-height: 60px; }
  .brand > span:last-child { display: none; }
  .nav > a, .nav .button-quiet { min-height: 40px; padding-inline: 9px; font-size: .86rem; }
  .heading-actions { align-items: stretch; flex-direction: column; }
  .heading-actions > form .button { width: 100%; }
  .course-card { grid-template-columns: 1fr; }
  .course-icon { width: 42px; height: 42px; }
  .course-heading { align-items: flex-start; flex-direction: column; }
  .course-meta { grid-template-columns: 1fr; }
  .run-status-row { flex-direction: column; }
  .progress-label { align-items: flex-start; flex-direction: column; gap: 2px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .transfer-metric-grid { grid-template-columns: 1fr; }
  .connection-heading { grid-template-columns: 44px 1fr; }
  .connection-heading .status { grid-column: 1 / -1; }
  .connection-meta { grid-template-columns: 1fr; }
  .auth-intro { flex-direction: column; gap: 12px; }
  .auth-steps { grid-template-columns: 1fr; }
  .auth-steps li { min-height: 56px; }
  .auth-panel { padding: 16px; }
  .auth-stage-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .auth-form .button { width: 100%; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: grid; grid-template-columns: minmax(90px, .45fr) 1fr; gap: 10px; padding: 7px 0; border: 0; }
  td::before { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; content: attr(data-label); }
  td:not([data-label]) { display: block; }
}
