:root {
  --color-primary: #1e3a5f;
  --color-primary-2: #254d73;
  --color-accent: #2563eb;
  --color-green: #0f766e;
  --color-warning: #b45309;
  --color-danger: #dc2626;
  --color-bg: #f6f8fb;
  --color-surface: #ffffff;
  --color-surface-2: #eef3f8;
  --color-border: #d7dee8;
  --color-text: #182230;
  --color-muted: #64748b;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.10);
}

[data-theme="dark"] {
  --color-primary: #111827;
  --color-primary-2: #263241;
  --color-accent: #60a5fa;
  --color-green: #2dd4bf;
  --color-warning: #fbbf24;
  --color-danger: #f87171;
  --color-bg: #0f141b;
  --color-surface: #18212d;
  --color-surface-2: #111827;
  --color-border: #334155;
  --color-text: #f1f5f9;
  --color-muted: #a3b0c2;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app { flex: 1; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f4c3a 60%, #0f766e 100%);
}
.auth-card {
  width: min(100%, 430px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card.wide { width: min(100%, 620px); }
.auth-logo { display: block; height: 46px; margin: 0 auto 18px; max-width: 100%; }
[data-theme="dark"] .auth-logo { filter: brightness(1.6) saturate(0.8); }
.company-logo { display: block; max-width: 180px; max-height: 72px; margin: 0 auto 18px; }
h1 { margin: 0 0 18px; font-size: 1.6rem; line-height: 1.2; }
h2 { margin: 0 0 12px; font-size: 1rem; }
.muted { color: var(--color-muted); }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--color-muted); font-size: .88rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 40px;
}
textarea { resize: vertical; min-height: 92px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, .22); border-color: var(--color-accent); }
.inline-field { display: flex; gap: 8px; align-items: center; }
.inline-field input { min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
}
.btn:disabled { opacity: .65; cursor: wait; }
.btn.primary { background: var(--color-accent); color: white; }
.btn.secondary { background: var(--color-surface-2); border-color: var(--color-border); color: var(--color-text); }
.btn.danger { background: var(--color-danger); color: white; }
.btn.microsoft { width: 100%; background: var(--color-primary); color: white; margin-bottom: 18px; }
.btn.small { min-height: 32px; padding: 6px 10px; }
.link-btn, .icon-btn {
  border: 0;
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  border-radius: 6px;
  padding: 6px 8px;
}
.icon-btn:hover, .link-btn:hover { background: var(--color-surface-2); }
.danger { color: var(--color-danger); }

.topbar {
  height: 58px;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(200px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--color-primary);
  color: white;
}
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; font-weight: 750; }
.brand img { height: 30px; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a { padding: 8px 10px; border-radius: 6px; text-decoration: none; }
.nav-links a:hover { background: rgba(255,255,255,.12); }
.nav-account { display: flex; align-items: center; justify-content: end; gap: 8px; min-width: 0; }
.account-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }

.page { width: min(1240px, calc(100% - 32px)); margin: 24px auto 56px; }
.page.narrow { width: min(820px, calc(100% - 32px)); }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a, .tabs button {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius);
  padding: 8px 12px;
  text-decoration: none;
  cursor: pointer;
}
.tabs .active, .tabs button.active { background: var(--color-primary-2); color: white; border-color: var(--color-primary-2); }
.panel, .table-shell, .drop-zone, .manual-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15,23,42,.05);
}
.panel { padding: 18px; margin-bottom: 16px; overflow-x: auto; }

.toolbar, .fetch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0;
}
.crumbs { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 220px; flex-wrap: wrap; }
.crumbs button { border: 0; background: transparent; color: var(--color-accent); cursor: pointer; padding: 6px; }
.fetch-row input:last-child { max-width: 280px; margin-left: auto; }

.drop-zone {
  padding: 24px;
  text-align: center;
  border-style: dashed;
  cursor: pointer;
}
.drop-zone.drag-over { border-color: var(--color-accent); background: rgba(37,99,235,.08); }
.drop-title { font-weight: 750; }
.drop-sub { color: var(--color-muted); margin-top: 4px; }
.upload-list { display: grid; gap: 8px; margin-top: 10px; }
.upload-row { display: grid; grid-template-columns: minmax(100px, 1fr) minmax(100px, 2fr) 48px 24px; gap: 8px; align-items: center; }
.progress { height: 8px; background: var(--color-surface-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--color-green); }

.table-shell { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
th { color: var(--color-muted); font-size: .78rem; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; flex-wrap: wrap; }
.name-link { border: 0; background: transparent; color: var(--color-accent); cursor: pointer; padding: 0; font-weight: 700; }
.file-name { font-weight: 650; }
.empty, .error { text-align: center; padding: 32px; color: var(--color-muted); }
.error { color: var(--color-danger); }

.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-form .full { grid-column: 1 / -1; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .58);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}
.modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
}
.modal-head, .modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--color-border);
}
.modal-actions { justify-content: flex-end; border-top: 1px solid var(--color-border); border-bottom: 0; }
.modal-body { padding: 18px; }

.upload-panel {
  position: fixed;
  bottom: 18px;
  left: 18px;
  width: min(400px, calc(100vw - 36px));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  display: grid;
  gap: 8px;
  z-index: 35;
}
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.login-link-input { min-width: 0; width: 200px; font-size: .8rem; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .82rem; }
.upload-cancel {
  border: 0; background: transparent; color: var(--color-muted);
  cursor: pointer; font-size: 1rem; padding: 0; line-height: 1; justify-self: center;
}
.upload-cancel:hover { color: var(--color-danger); }
.upload-row.done b { color: var(--color-green); }
.upload-row.done .progress i { background: var(--color-green); width: 100% !important; }
.upload-row.failed b { color: var(--color-danger); }
.upload-row.failed .progress i { background: var(--color-danger); }
.upload-row.cancelled b { color: var(--color-muted); }
.upload-row.cancelled .progress i { background: var(--color-muted); }

.app-footer {
  text-align: center;
  padding: 14px;
  font-size: .78rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}
.app-footer a { color: var(--color-accent); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

#toast-root { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 40; }
.toast {
  transform: translateY(8px);
  opacity: 0;
  transition: .18s ease;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast-error { background: var(--color-danger); }
.toast-success { background: var(--color-green); }
.toast-warning { background: var(--color-warning); }

.notice { border-radius: var(--radius); padding: 12px; margin: 12px 0; border: 1px solid var(--color-border); }
.notice.warning { background: rgba(180, 83, 9, .12); color: var(--color-warning); }
.notice.success { background: rgba(15, 118, 110, .12); color: var(--color-green); }
.message { white-space: pre-wrap; background: var(--color-surface-2); border-radius: var(--radius); padding: 12px; }
.share-summary { display: grid; gap: 6px; border: 1px solid var(--color-border); border-radius: var(--radius); padding: 12px; margin: 16px 0; }
.code-input { text-align: center; font-size: 1.4rem; letter-spacing: 4px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--color-border); border-top-color: var(--color-accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.secret-box { text-wrap: wrap; white-space: pre-wrap; background: var(--color-surface-2); padding: 16px; border-radius: var(--radius); border: 1px solid var(--color-border); }
.metric { display: inline-grid; gap: 4px; padding: 12px 16px; background: var(--color-surface-2); border-radius: var(--radius); margin-bottom: 14px; }
.metric b { font-size: 1.3rem; }
.metric span { color: var(--color-muted); }
.qr { width: 190px; height: 190px; justify-self: center; }
.manual-section { padding: 14px 18px; margin: 12px 0; }
.manual-section summary { cursor: pointer; }
.manual-section h2 { display: inline; }

@media (max-width: 820px) {
  .topbar {
    height: auto;
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .nav-links, .nav-account { justify-content: start; flex-wrap: wrap; }
  .page-head { align-items: stretch; flex-direction: column; }
  .grid-form { grid-template-columns: 1fr; }
  .inline-field { flex-direction: column; align-items: stretch; }
  .fetch-row input:last-child { max-width: none; margin-left: 0; }
  .upload-row { grid-template-columns: 1fr; }
}
