/* ---------- Theme tokens ---------- */
:root,
[data-theme="light"] {
  --bg:            #f6f7fa;
  --bg-elevated:   #ffffff;
  --card:          #ffffff;
  --text:          #151617;
  --text-subtle:   #293244;
  --muted:         #7d828b;
  --border:        #e3e8f1;
  --border-strong: #d0d8e8;
  --input-bg:      #ffffff;

  --primary:       #269a3c;
  --primary-hover: #1f8232;
  --primary-weak:  #d8f5e3;
  --accent:        #328fe6;

  --error:         #b91c1c;
  --error-bg:      #fff1f2;
  --warning-bg:    #fff7ed;
  --warning-border:#fdba74;
  --warning-text:  #92400e;
  --success:       #16a34a;

  --code-bg:       #eceff6;
  --shadow-sm:     0 1px 2px rgba(15, 17, 19, 0.04);
  --shadow-md:     0 4px 16px rgba(15, 17, 19, 0.06);
}

[data-theme="dark"] {
  --bg:            #0f1113;
  --bg-elevated:   #15181c;
  --card:          #1a1d21;
  --text:          #eceff6;
  --text-subtle:   #c8cde0;
  --muted:         #858fa3;
  --border:        #293244;
  --border-strong: #384056;
  --input-bg:      #14171b;

  --primary:       #43a047;
  --primary-hover: #52ae30;
  --primary-weak:  #143d1c;
  --accent:        #5eb0ff;

  --error:         #f87171;
  --error-bg:      #2a0f12;
  --warning-bg:    #2a1d0a;
  --warning-border:#7c5014;
  --warning-text:  #fbbf24;
  --success:       #4ade80;

  --code-bg:       #24282f;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md:     0 4px 16px rgba(0, 0, 0, 0.45);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.18s ease, color 0.18s ease;
}

/* ---------- Header ---------- */
header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-weak);
  display: inline-block;
}

nav {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14px;
  color: var(--muted);
}

#userEmail { font-weight: 500; color: var(--text-subtle); }

/* ---------- Layout ---------- */
main {
  max-width: 720px;
  margin: 32px auto;
  padding: 0 16px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  border: none;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab:hover { color: var(--text-subtle); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ---------- Cards / forms ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

input[type="email"],
input[type="password"],
input[type="file"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
  background: var(--input-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-weak);
}

input[type="file"]::file-selector-button {
  background: var(--primary-weak);
  color: var(--primary);
  border: none;
  padding: 6px 12px;
  margin-right: 10px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
}

/* ---------- Buttons ---------- */
button {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover:not(:disabled) { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

#btnTheme {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 40px;
}

#btnTheme svg { width: 16px; height: 16px; }
html[data-theme="light"] #btnTheme .icon-sun { display: none; }
html[data-theme="dark"]  #btnTheme .icon-moon { display: none; }

/* ---------- Text bits ---------- */
.hint {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}

.warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin: 0;
}

code {
  background: var(--code-bg);
  color: var(--text-subtle);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.error {
  color: var(--error);
  font-size: 14px;
  margin: 0;
}
.error:empty { display: none; }

.status {
  color: var(--success);
  font-size: 14px;
  margin: 0;
}
.status:empty { display: none; }

.view { display: block; }
.view[hidden] { display: none; }
[hidden] { display: none !important; }

/* ---------- Progress bar ---------- */
.progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.progress-bar {
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 999px;
  animation: progress-slide 1.4s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* Determinate variant: width is driven by JS, no sliding animation. */
.progress-determinate {
  height: 10px;
  margin-bottom: 22px;
}
.progress-determinate .progress-bar {
  position: relative;
  inset: auto;
  height: 100%;
  left: 0;
  animation: none;
  transition: width 200ms ease-out;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-size: 0.85em;
  color: var(--muted, #666);
}
.progress-stage { flex: 1; }
.progress-pct { font-variant-numeric: tabular-nums; }

.download-again {
  align-self: flex-start;
}

/* ---------- Type-selection checkboxes ---------- */
.types-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
.types-group legend {
  padding: 0 6px;
  font-size: 13px;
  color: var(--muted);
}
.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.check input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ---------- History ---------- */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}
.history-row .badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-weak);
  color: var(--primary);
  font-weight: 500;
}
.history-row .badge.restore {
  background: var(--code-bg);
  color: var(--text-subtle);
}
.history-meta {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 15px; }
  main { margin: 16px auto; }
  .card { padding: 18px; }
}
