:root {
  color-scheme: light;
  --page: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f5f5f5;
  --ink: #212121;
  --muted: #737373;
  --subtle: #a3a3a3;
  --line: #e5e5e5;
  --line-strong: #d4d4d4;
  --button: #3a3a3a;
  --button-hover: #262626;
  --brand: #f7a917;
  --danger: #b42318;
  --radius: 6px;
}

* { box-sizing: border-box; }

html { background: var(--page); }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 58px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(12px);
}

.header-inner {
  width: min(1152px, calc(100% - 32px));
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}

.brand img {
  width: 20px;
  height: 27px;
  margin-right: 10px;
  object-fit: contain;
}

.brand-name { font-size: 15px; font-weight: 700; }

.brand-product {
  margin-left: 9px;
  padding-left: 9px;
  border-left: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-menu {
  position: relative;
  height: 36px;
}

.header-menu > summary { list-style: none; }
.header-menu > summary::-webkit-details-marker { display: none; }

.header-menu[open] > summary {
  background: var(--surface-muted);
  color: var(--ink);
}

.header-popover {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 30;
  width: 208px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 16px 38px rgba(33, 33, 33, .14);
  backdrop-filter: blur(12px);
}

.popover-label {
  display: block;
  padding: 5px 9px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.header-popover a,
.popover-current {
  min-height: 36px;
  padding: 0 9px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
  text-decoration: none;
}

.header-popover a:hover { background: var(--surface-muted); }

.header-popover svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
}

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

.current-mark {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
}

.header-actions form,
.row-actions form,
.token-row form { margin: 0; }

.account-name {
  max-width: 180px;
  margin: 0 7px 0 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-shell {
  width: min(1152px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 72px;
}

.page-heading {
  min-height: 66px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.page-heading h1,
.login-heading h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.page-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.count {
  padding-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.alerts {
  display: grid;
  gap: 8px;
  margin: 6px 0 20px;
}

.alert {
  padding: 10px 12px;
  border: 1px solid #bbd9cb;
  border-radius: var(--radius);
  background: #f1f8f4;
  color: #245943;
  font-size: 13px;
}

.alert.error {
  border-color: #f2b8b5;
  background: #fff1f0;
  color: #8e1b13;
}

.content-section { margin-top: 30px; }

.section-heading {
  min-height: 34px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.upload-section {
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.upload-picker { min-width: 0; }

.upload-drop {
  height: 58px;
  padding: 8px 9px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.upload-drop:hover,
.upload-drop.is-dragging {
  border-color: var(--muted);
  background: var(--surface-muted);
}

.upload-drop.has-file { border-style: solid; border-color: var(--brand); }

.upload-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--muted);
}

.upload-icon svg,
.choose-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-copy { min-width: 0; }

.upload-copy strong,
.upload-copy > span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-copy strong { color: var(--ink); font-size: 13px; font-weight: 650; }
.upload-copy > span { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 400; }

.choose-action {
  height: 34px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.choose-action svg { width: 15px; height: 15px; }

label {
  min-width: 0;
  display: grid;
  gap: 6px;
}

label > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input, select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}

input[type="file"] { padding: 6px; }

.upload-grid select { height: 36px; }

input:focus, select:focus {
  outline: 2px solid rgba(247, 169, 23, .24);
  border-color: var(--brand);
}

.primary-button,
.secondary-button {
  min-height: 38px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.primary-button { background: var(--button); color: #ffffff; }
.primary-button:hover { background: var(--button-hover); }
.secondary-button { background: var(--surface-muted); color: var(--ink); border: 1px solid var(--line); }
.secondary-button:hover { background: var(--line); }
.primary-button svg { width: 16px; height: 16px; }

.upload-submit {
  height: 36px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  background: #212121;
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  transition: background-color 150ms ease;
}

.upload-submit:hover { background: #3a3a3a; }
.upload-submit svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-list {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.file-row {
  min-height: 76px;
  padding: 14px 12px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.file-row:last-child { border-bottom: 0; }

.file-symbol { color: var(--subtle); }

.file-symbol svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-data { min-width: 0; }

.file-data strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-data p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.metadata {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px 12px;
  color: var(--muted);
  font-size: 11px;
}

.expired { color: var(--danger); font-weight: 650; }
.row-actions { display: flex; gap: 3px; }

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover { background: var(--surface-muted); color: var(--ink); }
.icon-button.danger:hover { background: #fff0ef; color: var(--danger); }

.header-icon { border-radius: 8px; }

.header-icon svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }

.empty {
  padding: 38px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty.compact { padding: 18px; }

.api-section {
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.api-heading code {
  color: var(--muted);
  font-size: 11px;
}

.token-reveal {
  margin: 4px 0 16px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #e7c981;
  border-radius: var(--radius);
  background: #fff9e8;
}

.token-reveal code { overflow: auto; font-size: 12px; }

.token-form {
  display: grid;
  grid-template-columns: minmax(220px, 420px) auto;
  align-items: end;
  gap: 12px;
}

.token-list {
  margin-top: 16px;
  border-top: 1px solid var(--line);
}

.token-row {
  padding: 12px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.token-row strong { display: block; font-size: 13px; }
.token-row span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.text-danger { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 12px; }

.login-shell {
  min-height: calc(100vh - 58px);
  padding: 32px 24px;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(390px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 16px 42px rgba(33, 33, 33, .07);
}

.login-heading { margin-bottom: 24px; }

.login-heading img {
  width: 19px;
  height: 25px;
  margin-right: 8px;
  object-fit: contain;
  vertical-align: middle;
}

.login-heading > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  vertical-align: middle;
}

.login-heading h1 { margin-top: 18px; }
.stack { display: grid; gap: 15px; }
.stack .primary-button { width: 100%; margin-top: 4px; }

.dark {
  color-scheme: dark;
  --page: #262626;
  --surface: #3a3a3a;
  --surface-muted: #454545;
  --ink: #fafafa;
  --muted: #d4d4d4;
  --subtle: #a3a3a3;
  --line: #525252;
  --line-strong: #737373;
  --button: #f5f5f5;
  --button-hover: #e5e5e5;
}

.dark .app-header { background: rgba(58, 58, 58, .88); }
.dark .header-popover { background: rgba(38, 38, 38, .97); box-shadow: 0 16px 38px rgba(0, 0, 0, .28); }
.dark .primary-button { color: #212121; }
.dark .upload-submit { background: #f5f5f5; color: #212121; }
.dark .upload-submit:hover { background: #ffffff; }
.dark .icon-button.danger:hover { background: #522e2d; }
.dark .alert { border-color: #35604d; background: #2c473b; color: #cae7d9; }
.dark .alert.error { border-color: #7d4845; background: #4b3030; color: #ffd0cc; }
.dark .token-reveal { border-color: #8a6b29; background: #493f29; }
.dark .login-panel { box-shadow: 0 16px 42px rgba(0, 0, 0, .18); }
.dark .theme-toggle .sun-icon { display: block; }
.dark .theme-toggle .moon-icon { display: none; }

@media (max-width: 680px) {
  .header-inner,
  .page-shell { width: min(100% - 24px, 1152px); }
  .brand-name { display: none; }
  .brand-product { margin-left: 0; padding-left: 0; border-left: 0; color: var(--ink); font-size: 14px; font-weight: 650; }
  .account-name { display: none; }
  .page-shell { padding-top: 25px; }
  .page-heading { min-height: 62px; }
  .page-heading h1 { font-size: 23px; }
  .upload-grid { grid-template-columns: 1fr; }
  .upload-drop { grid-template-columns: 36px minmax(0, 1fr); }
  .choose-action { display: none; }
  .upload-grid .upload-submit,
  .token-form .secondary-button { width: 100%; }
  .file-row { grid-template-columns: 24px minmax(0, 1fr); padding-inline: 9px; }
  .row-actions { grid-column: 2; }
  .token-form { grid-template-columns: 1fr; }
  .api-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .login-panel { padding: 25px 22px; }
}
