:root {
  color-scheme: light;
  --primary: #0052ff;
  --primary-active: #003ecc;
  --primary-disabled: #a8b8cc;
  --canvas: #ffffff;
  --ink: #0a0b0d;
  --body: #5b616e;
  --muted: #7c828a;
  --muted-soft: #a8acb3;
  --surface-soft: #f7f7f7;
  --surface-strong: #eef0f3;
  --surface-dark: #0a0b0d;
  --surface-dark-elevated: #16181c;
  --hairline: #dee1e6;
  --hairline-soft: #eef0f3;
  --error: #cf202f;
  --semantic-up: #05b169;
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 100px;
  --container: 1200px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 14px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--canvas);
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--primary);
  border-width: 2px;
  padding: 13px 15px;
}

.hidden { display: none !important; }
.error { color: var(--error); margin-top: 12px; font-weight: 600; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(16px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--hairline-soft);
  backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.topbar-brand strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.topbar-brand span:not(.brand-mark) {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--body);
  font-size: 14px;
  font-weight: 500;
}

.topbar nav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  color: var(--ink);
}

/* ---- Auth ---- */
.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 80% 20%, rgba(0, 82, 255, 0.12), transparent 28%),
    var(--surface-soft);
}

.auth-card {
  width: min(100%, 430px);
  padding: 40px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  background: var(--canvas);
  box-shadow: var(--shadow-soft);
}

.auth-card h1 {
  font-size: 32px;
  font-weight: 400;
  line-height: 1.15;
}

.auth-card p {
  margin-top: 10px;
  color: var(--body);
  font-size: 15px;
}

.form-stack {
  display: grid;
  gap: 18px;
  margin-top: 28px;
}

.form-stack label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 600;
}

.form-stack button,
.upload-form button[type="submit"],
.cfop-submit {
  min-height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.form-stack button:hover,
.upload-form button[type="submit"]:hover,
.cfop-submit:hover {
  background: var(--primary-active);
}

.form-stack button:disabled,
.upload-form button[type="submit"]:disabled {
  background: var(--primary-disabled);
}

/* ---- Dashboard ---- */
.dashboard {
  width: min(100%, var(--container));
  margin: 0 auto;
  padding: 32px clamp(16px, 4vw, 32px) 80px;
}

.page-title {
  padding: 12px 0 4px;
}

.page-title h1 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0;
}

/* ---- Upload ---- */
.upload-panel,
.panel {
  margin-top: 24px;
  padding: 28px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  background: var(--canvas);
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: end;
}

.upload-form .field,
.upload-form .dropzone {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.upload-form .field input {
  font-weight: 400;
}

.upload-form .dropzone {
  cursor: pointer;
}

.upload-form .dropzone span {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-form .dropzone input {
  display: none;
}

.upload-form button[type="submit"] {
  min-width: 128px;
  align-self: start;
  margin-top: 27px;
}

/* ---- Active task ---- */
.task-card {
  margin-top: 22px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
}

.task-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  color: var(--body);
}

.task-header strong {
  color: var(--ink);
  font-weight: 600;
}

.task-header span,
.progress-cell {
  font-family: "JetBrains Mono", "Geist Mono", Consolas, monospace;
  font-weight: 500;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
}

.progress div {
  width: 0%;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--primary);
  transition: width .25s ease;
}

.downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* ---- Panel / table ---- */
.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 24px;
  font-weight: 400;
  line-height: 1.2;
}

.filters {
  display: flex;
  gap: 8px;
}

.filter-input {
  min-height: 40px;
  width: auto;
  min-width: 170px;
  padding: 10px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  font-size: 13px;
}

.filter-input:focus {
  padding: 9px 13px;
}

.table-wrap {
  overflow-x: auto;
}

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

thead th {
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody td {
  padding: 18px 14px;
  border-bottom: 1px solid var(--hairline-soft);
  color: var(--body);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.file-cell {
  max-width: 340px;
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-cell,
.progress-cell,
.count-cell,
.money-cell {
  white-space: nowrap;
}

.count-cell,
.money-cell {
  font-family: "JetBrains Mono", "Geist Mono", Consolas, monospace;
  color: var(--ink);
  font-weight: 500;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  max-width: 260px;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  color: var(--body);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-done {
  color: var(--semantic-up);
}

.status-error {
  color: var(--error);
}

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

/* ---- Downloads menu ---- */
.downloads-trigger {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.downloads-trigger:hover {
  background: var(--primary-active);
}

.downloads-trigger span {
  font-size: 12px;
}

.floating-menu,
.cfop-menu {
  position: absolute;
  z-index: 40;
  width: min(320px, calc(100vw - 24px));
}

.floating-menu-card,
.cfop-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--canvas);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.12);
}

.floating-menu-card strong,
.cfop-menu-head strong {
  padding: 6px 8px 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.menu-item {
  min-height: 42px;
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

.menu-item:hover {
  background: var(--surface-soft);
}

.menu-item.is-disabled,
.menu-item:disabled {
  color: var(--muted-soft);
  cursor: not-allowed;
}

.menu-item.is-disabled:hover,
.menu-item:disabled:hover {
  background: transparent;
}

/* ---- CFOP menu ---- */
.cfop-menu {
  width: min(340px, calc(100vw - 24px));
}

.cfop-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cfop-menu-close {
  min-height: 32px;
  width: 32px;
  border-radius: 9999px;
  background: var(--surface-strong);
  color: var(--ink);
}

.cfop-menu-actions {
  display: flex;
  gap: 8px;
  padding: 0 2px;
}

.cfop-menu-actions button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.cfop-options {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 2px;
}

.cfop-option {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  color: var(--ink);
}

.cfop-option:hover {
  background: var(--surface-soft);
}

.cfop-option input {
  min-height: 16px;
  width: 16px;
  margin: 0;
}

.cfop-error {
  margin: 0;
  padding: 0 8px;
  color: var(--error);
  font-size: 12px;
  font-weight: 600;
}

.cfop-submit {
  width: 100%;
  min-height: 40px;
  font-size: 14px;
}

/* ---- Breakpoints ---- */
@media (max-width: 900px) {
  .upload-form {
    grid-template-columns: 1fr;
  }

  .upload-form button[type="submit"] {
    width: 100%;
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px 16px;
  }

  .topbar nav {
    gap: 8px;
  }

  .dashboard {
    padding-top: 18px;
  }

  .upload-panel,
  .panel,
  .auth-card {
    border-radius: var(--radius-lg);
    padding: 22px;
  }

  .page-title {
    padding: 6px 0 0;
  }

  .filters {
    width: 100%;
    flex-direction: column;
  }

  .filter-input {
    width: 100%;
  }
}
