:root {
  --bg: #171717;
  --bg-card: #1e1e1e;
  --bg-surface: #242424;
  --bg-input: #1a1a1a;
  --text: #fafafa;
  --text-secondary: #b4b4b4;
  --text-muted: #898989;
  --text-subtle: #6b6b6b;
  --border: #2e2e2e;
  --border-light: #363636;
  --border-subtle: #242424;
  --accent: #3ecf8e;
  --accent-hover: #00c573;
  --accent-dim: rgba(62, 207, 142, 0.15);
  --accent-border: rgba(62, 207, 142, 0.3);
  --success: #3ecf8e;
  --success-bg: rgba(62, 207, 142, 0.1);
  --error: #e5484d;
  --error-bg: rgba(229, 72, 77, 0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 9999px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ───── Header ───── */
.app-header {
  background: #0f0f0f;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.2px;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-gray { background: #4d4d4d; }
.dot-green {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.4);
}

/* ───── Container ───── */
.container {
  max-width: 700px;
  margin: 0 auto;
  padding: 32px 20px;
}

/* ───── Cards ───── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.card h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.2px;
}

/* ───── Step Flow ───── */
.step-flow {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  margin: 0 0 16px;
}

.step-box {
  display: flex;
  gap: 16px;
  padding: 18px 20px;
  border-radius: var(--radius);
  align-items: flex-start;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  transition: all 0.25s ease;
}

.step-box.active {
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.step-box.done {
  border-color: var(--accent);
  background: var(--success-bg);
  opacity: 0.85;
}

.step-box.done .step-box-num {
  background: var(--accent);
  color: #0f0f0f;
}

.step-box-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  background: #0f0f0f;
  color: var(--accent);
  border-radius: 50%;
  font-weight: 500;
  font-size: 15px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.step-box-body { flex: 1; }

.step-box-body strong {
  display: block;
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

.step-desc {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.step-desc a {
  color: var(--accent-hover);
  font-weight: 500;
  text-decoration: none;
}

.step-desc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ───── Code display ───── */
.big-code {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 5px;
  padding: 14px 18px;
  background: #0f0f0f;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  text-align: center;
  margin: 8px 0;
  color: var(--accent);
  cursor: pointer;
  user-select: all;
  transition: all 0.15s;
}

.big-code:hover {
  border-color: var(--accent);
  background: #1a1a1a;
}

.code-placeholder {
  color: var(--text-subtle);
  font-size: 14px;
  letter-spacing: 0;
  font-weight: 400;
}

.copy-hint {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.3s;
  text-align: center;
}

.copy-hint.visible { opacity: 1; }

/* ───── Buttons ───── */
.btn {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: all 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  line-height: 1;
}

.btn:hover {
  border-color: var(--border-light);
  background: var(--bg-surface);
}

.btn:active { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: #0f0f0f;
  color: var(--text);
  border: 1px solid var(--text);
  border-radius: var(--radius-pill);
  font-weight: 500;
}

.btn-primary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.btn-danger:hover {
  background: var(--error);
  color: #fff;
}

.btn-small {
  padding: 7px 14px;
  min-height: 38px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-large {
  padding: 14px 28px;
  font-size: 16px;
  min-height: 52px;
  width: 100%;
  border-radius: var(--radius-pill);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn-row:first-child { margin-top: 0; }

/* ───── Fieldsets ───── */
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 22px;
}

legend {
  font-weight: 500;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ───── Inputs ───── */
input[type="text"], input[type="date"] {
  font-family: inherit;
  font-size: 15px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  min-height: 44px;
  width: 100%;
  transition: border-color 0.15s;
  color: var(--text);
}

input[type="text"]:focus, input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
  filter: brightness(0.9);
}

::placeholder { color: var(--text-subtle); }

/* ───── Date row ───── */
.date-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.date-row label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.date-row input[type="date"] {
  width: auto;
  min-width: 150px;
  color-scheme: dark;
}

/* ───── Preset buttons ───── */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.preset-btn {
  padding: 8px 14px;
  min-height: 38px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.preset-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ───── Path display ───── */
.path-display {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.path-display code {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--accent);
  word-break: break-all;
}

/* ───── Date text ───── */
#dateRangeText {
  text-align: center;
  font-weight: 500;
}

/* ───── Path row ───── */
.path-row {
  display: flex;
  gap: 8px;
}

.path-row input { flex: 1; }

/* ───── Folder tree ───── */
.folder-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.folder-tree {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--bg-input);
}

.folder-node {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}

.folder-node:hover {
  background: var(--accent-dim);
}

.folder-node input[type="checkbox"] {
  margin-right: 10px;
}

.folder-children { padding-left: 26px; }

.folder-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.folder-count {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 8px;
}

/* ───── Progress ───── */
.progress-bar {
  height: 8px;
  background: var(--bg-surface);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--border-subtle);
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 300ms ease-out;
  border-radius: 4px;
}

.progress-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  padding: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  text-align: center;
  border: 1px solid var(--border);
}

.stat-box strong {
  font-size: 26px;
  display: block;
  font-weight: 500;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  margin-top: 2px;
}

.status-line {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ───── Event log ───── */
.event-log {
  max-height: 180px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  background: #0f0f0f;
  border-radius: var(--radius-sm);
  padding: 10px;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  line-height: 1.6;
  color: var(--text-muted);
}

details { margin-top: 10px; }

details summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 6px 0;
}

details summary:hover {
  color: var(--accent);
}

/* ───── Resume banner ───── */
.banner {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  margin-bottom: 18px;
}

.banner strong {
  color: var(--accent);
  font-size: 14px;
}

.banner label {
  display: block;
  margin-top: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ───── Results ───── */
.result-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.result-list li {
  padding: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.result-num {
  font-size: 26px;
  display: block;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 2px;
  line-height: 1.2;
}

/* ───── Polling ───── */
.polling-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 12px;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ───── Spinner ───── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ───── Error ───── */
.error {
  background: var(--error-bg);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.error-list { margin: 6px 0 0; padding-left: 18px; }

/* ───── Utils ───── */
.muted {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.hidden { display: none !important; }

/* ───── Footer ───── */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-subtle);
  font-size: 12px;
}

/* ───── Touch / iPad ───── */
@media (hover: none) {
  .btn:hover {
    border-color: var(--border);
    color: inherit;
  }
  .btn-primary:hover {
    border-color: var(--text);
    color: var(--text);
  }
  .folder-node:hover { background: transparent; }
}

/* ───── Mobile ───── */
@media (max-width: 600px) {
  .container { padding: 16px 12px; }
  .card { padding: 20px; }
  .app-header { padding: 12px 14px; }
  .app-header h1 { font-size: 15px; }
  .big-code { font-size: 22px; letter-spacing: 3px; padding: 10px; }
  .date-row { flex-direction: column; }
  .date-row input[type="date"] { width: 100%; min-width: auto; }
  .path-row { flex-direction: column; }
  .progress-stats { grid-template-columns: repeat(2, 1fr); }
  .result-list { grid-template-columns: repeat(2, 1fr); }
  .step-box { padding: 14px 16px; }
  .step-box-num { width: 30px; height: 30px; min-width: 30px; font-size: 13px; }
  .btn-large { padding: 12px 20px; font-size: 15px; min-height: 48px; }
}
