:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --bg-soft: #eef3f1;
  --panel: #ffffff;
  --panel-strong: #f7faf9;
  --line: #d8e1dd;
  --text: #17201e;
  --muted: #5d6b66;
  --subtle: #7c8b86;
  --accent: #28b89b;
  --accent-strong: #1fa687;
  --warn: #b97908;
  --danger: #c74444;
  --ok: #218b5a;
  --shadow: 0 18px 50px rgba(25, 45, 40, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 22% 0%, rgba(40, 184, 155, 0.16), transparent 30rem),
    linear-gradient(135deg, #f6f8f8 0%, #eef4f1 48%, #f7f9fa 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #28b89b;
  color: #061613;
  font-weight: 900;
  letter-spacing: 0;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

.login-panel h1,
.topbar h1 {
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

.login-panel p,
.panel-heading p,
.eyebrow,
.muted,
.dialog-head p {
  color: var(--muted);
}

.login-panel p {
  margin-top: 10px;
  margin-bottom: 24px;
}

.stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 104px;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(40, 184, 155, 0.18);
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  color: var(--text);
}

.primary-btn {
  background: var(--accent);
  color: #071815;
  font-weight: 800;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.ghost-btn,
.icon-btn {
  background: #f7faf9;
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost-btn:hover,
.icon-btn:hover {
  border-color: #4d5965;
}

.ghost-btn.danger {
  color: #ffc9c9;
}

.inline-error {
  margin-top: 14px;
  color: #7c1f1f;
  background: rgba(244, 109, 109, 0.12);
  border: 1px solid rgba(199, 68, 68, 0.25);
  padding: 10px 12px;
  border-radius: 8px;
}

.main-view {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(420px, 1.4fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  font-size: 20px;
  line-height: 1.2;
}

.panel-heading p {
  margin-top: 4px;
  font-size: 14px;
}

.status-panel,
.current-panel,
.history-panel,
.library-panel {
  grid-column: 2;
}

.task-panel {
  grid-row: span 2;
  position: sticky;
  top: 18px;
}

.history-panel,
.library-panel {
  grid-column: 1 / -1;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.status-pill.ok {
  color: #126943;
  background: rgba(103, 211, 145, 0.16);
  border-color: rgba(33, 139, 90, 0.24);
}

.status-pill.warn {
  color: #80550b;
  background: rgba(243, 189, 78, 0.18);
  border-color: rgba(185, 121, 8, 0.24);
}

.status-pill.danger {
  color: #8d2a2a;
  background: rgba(244, 109, 109, 0.13);
  border-color: rgba(244, 109, 109, 0.32);
}

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.switch-line {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  color: var(--text);
  margin: 0;
}

.switch-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

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

.metric {
  min-height: 88px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.metric span {
  color: var(--subtle);
  font-size: 13px;
}

.metric strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

.progress-bar {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf3f0;
  border: 1px solid var(--line);
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8be6c9);
  transition: width 180ms ease;
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.current-track {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #f7faf9;
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.log-box {
  margin: 14px 0 0;
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f7faf9;
  color: #17201e;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.55;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.record-main {
  min-width: 0;
}

.record-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.record-title strong {
  overflow-wrap: anywhere;
}

.record-meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.record-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.library-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-cell {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.summary-cell span {
  display: block;
  color: var(--subtle);
  font-size: 12px;
  margin-bottom: 5px;
}

.summary-cell strong {
  overflow-wrap: anywhere;
}

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

.folder-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  padding: 14px;
}

.folder-card h3 {
  margin: 0;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.folder-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.folder-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-dialog {
  width: min(920px, calc(100% - 24px));
  max-height: min(82vh, 820px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
}

.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-body {
  padding: 18px;
  overflow: auto;
  max-height: calc(82vh - 92px);
}

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

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.file-row strong,
.file-row span {
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

@media (max-width: 980px) {
  .main-view {
    padding: 20px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .task-panel,
  .status-panel,
  .current-panel,
  .history-panel,
  .library-panel {
    grid-column: 1;
    grid-row: auto;
    position: static;
  }

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

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

@media (max-width: 620px) {
  .main-view {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .record-actions,
  .folder-actions {
    justify-content: stretch;
  }

  .topbar-actions button,
  .record-actions button,
  .folder-actions button {
    flex: 1 1 auto;
  }

  .metric-grid,
  .library-summary,
  .library-grid {
    grid-template-columns: 1fr;
  }

  .record-item,
  .file-row {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .panel-heading {
    flex-direction: column;
  }

  .option-row {
    align-items: flex-start;
    flex-direction: column;
  }
}
