/* ============================================================
   TIWEBA Upload — tema claro/escuro, sem dependências externas
   ============================================================ */

:root {
  --bg: #f5f6fb;
  --bg-glow-1: rgba(99, 102, 241, .14);
  --bg-glow-2: rgba(14, 165, 233, .12);
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e7ef;
  --border-strong: #cfd4e2;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #5b5ef0;
  --accent-2: #0ea5e9;
  --accent-soft: rgba(91, 94, 240, .09);
  --accent-ring: rgba(91, 94, 240, .28);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, .1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .08);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 28px -8px rgba(15, 23, 42, .12);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e17;
    --bg-glow-1: rgba(99, 102, 241, .18);
    --bg-glow-2: rgba(14, 165, 233, .10);
    --surface: #121624;
    --surface-2: #171c2d;
    --border: #232a3d;
    --border-strong: #323b54;
    --text: #e8ebf4;
    --text-2: #c3c9d9;
    --muted: #8a93aa;
    --accent: #7c80ff;
    --accent-soft: rgba(124, 128, 255, .12);
    --accent-ring: rgba(124, 128, 255, .35);
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, .12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -10px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  min-height: 100vh;
  font: 15px/1.55 var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 10% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: .95rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Estrutura ---------- */

.container { max-width: 760px; margin: 0 auto; padding: 32px 20px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.footnote {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 22px; font-size: .82rem; color: var(--muted); text-align: center;
}
.footnote svg { width: 16px; height: 16px; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px max(20px, calc((100vw - 1080px) / 2));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: -.03em; }
.brand-sub {
  font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 999px;
}
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
  color: #fff; box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .7);
}
.brand-mark svg { width: 18px; height: 18px; stroke-width: 2.6; }
.brand-mark-lg { width: 52px; height: 52px; border-radius: 14px; }
.brand-mark-lg svg { width: 26px; height: 26px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .88rem; font-weight: 500; color: var(--text-2);
}
.avatar {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
}

/* ---------- Botões ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
.btn:disabled { opacity: .7; cursor: default; }
.btn svg { width: 17px; height: 17px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: .88rem; }
.btn-block { width: 100%; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2)));
  box-shadow: 0 8px 20px -8px var(--accent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-ghost { color: var(--text-2); border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { border-color: var(--border-strong); background: var(--surface-2); }

.btn-link { height: auto; padding: 4px 6px; color: var(--accent); font-weight: 500; font-size: .88rem; }
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  border: 0; background: none; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.icon-btn svg { width: 17px; height: 17px; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */

.page-login .login-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 32px 20px;
}
.login-card { width: 100%; max-width: 400px; padding: 36px 32px 32px; }
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; margin-bottom: 28px; }
.login-brand .brand-mark { margin-bottom: 6px; }
.login-brand p { font-size: .92rem; max-width: 30ch; }

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 6px; font-size: .85rem; font-weight: 600; color: var(--text-2); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input {
  width: 100%; height: 46px; padding: 0 44px 0 42px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input-wrap input:hover { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--accent)); }
.input-wrap input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-ring); }
.input-icon { position: absolute; left: 13px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.input-action {
  position: absolute; right: 6px; display: grid; place-items: center;
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); cursor: pointer;
}
.input-action:hover { color: var(--text); background: var(--border); }
.input-action:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.input-action svg { width: 18px; height: 18px; }
.input-action .eye-closed, .input-action[aria-pressed="true"] .eye-open { display: none; }
.input-action[aria-pressed="true"] .eye-closed { display: block; }

#login-btn { margin-top: 8px; }
#login-btn .spinner { display: none; width: 16px; height: 16px; }
#login-btn.is-loading .spinner { display: block; }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; margin-bottom: 18px; border-radius: var(--radius-sm);
  font-size: .88rem; font-weight: 500;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); }

.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- Upload ---------- */

.upload-card { padding: 28px; }
.card-head { margin-bottom: 20px; }
.card-head p { margin-top: 4px; font-size: .93rem; }

.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 44px 24px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: 14px;
  background: var(--surface-2);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.dropzone:hover { border-color: color-mix(in srgb, var(--border-strong) 40%, var(--accent)); }
.dropzone:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.dropzone.is-dragover {
  border-color: var(--accent); border-style: solid;
  background: var(--accent-soft);
}
.dropzone.is-dragover .dz-icon { transform: translateY(-4px) scale(1.06); }

.dz-icon {
  display: grid; place-items: center; width: 60px; height: 60px; margin-bottom: 8px;
  border-radius: 16px; color: var(--accent); background: var(--accent-soft);
  transition: transform .2s;
}
.dz-icon svg { width: 30px; height: 30px; stroke-width: 1.8; }
.dz-title { font-size: 1.05rem; font-weight: 600; }
.dz-sub { font-size: .9rem; color: var(--muted); }
.dz-link { color: var(--accent); font-weight: 600; }
.dz-limits {
  margin-top: 10px; font-size: .78rem; color: var(--muted);
  max-width: 52ch; line-height: 1.5; min-height: 1.2em;
}

.list-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 10px; }
.summary { flex: 1; font-size: .85rem; color: var(--muted); }

.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.file-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 10px 12px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
  animation: item-in .25s ease-out;
  transition: border-color .2s, background .2s;
}
@keyframes item-in { from { opacity: 0; transform: translateY(6px); } }

.file-badge {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 10px;
  font-size: .66rem; font-weight: 800; letter-spacing: .02em; text-transform: uppercase;
  color: var(--kind); background: color-mix(in srgb, var(--kind) 12%, transparent);
  --kind: #64748b;
}
.file-badge[data-kind="pdf"] { --kind: #e11d48; }
.file-badge[data-kind="image"] { --kind: #8b5cf6; }
.file-badge[data-kind="doc"] { --kind: #2563eb; }
.file-badge[data-kind="sheet"] { --kind: #059669; }
.file-badge[data-kind="slide"] { --kind: #ea580c; }
.file-badge[data-kind="archive"] { --kind: #ca8a04; }
.file-badge[data-kind="media"] { --kind: #db2777; }
.file-badge[data-kind="text"] { --kind: #0891b2; }

.file-body { flex: 1; min-width: 0; }
.file-row { display: flex; align-items: baseline; gap: 10px; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: .92rem; }
.file-size { flex: none; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { height: 5px; margin: 7px 0 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-bar {
  display: block; height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease-out;
}
.file-status { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.file-status code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .76rem; }

.file-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.state-icon { display: none; place-items: center; width: 32px; height: 32px; }
.state-busy { color: var(--accent); }
.state-ok { color: var(--success); }
.state-ok svg { width: 22px; height: 22px; stroke-width: 2.5; }
.retry-btn, .remove-btn { display: none; }

/* Estados do item */
.file-item[data-state="queued"] .progress-bar { width: 0; }
.file-item[data-state="uploading"] .state-busy,
.file-item[data-state="processing"] .state-busy { display: grid; }
.file-item[data-state="processing"] .progress-bar { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.file-item[data-state="done"] .state-ok { display: grid; }
.file-item[data-state="done"] .progress-bar { background: var(--success); }
.file-item[data-state="done"] .remove-btn { display: grid; }

.file-item[data-state="error"] { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--danger-soft); }
.file-item[data-state="error"] .progress { display: none; }
.file-item[data-state="error"] .file-status { color: var(--danger); font-weight: 500; margin-top: 3px; white-space: normal; }
.file-item[data-state="error"] .remove-btn { display: grid; }
.file-item[data-state="error"][data-retry="true"] .retry-btn { display: grid; }
.file-item[data-state="queued"] .remove-btn { display: grid; }

/* ---------- Responsivo ---------- */

@media (max-width: 560px) {
  .container { padding: 20px 14px 36px; }
  .upload-card { padding: 20px 16px; }
  .dropzone { padding: 32px 16px; }
  .brand-sub, .user-chip span:not(.avatar) { display: none; }
  .user-chip { padding: 4px; }
  .login-card { padding: 28px 22px 24px; }
  .file-item { gap: 10px; }
  .file-badge { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
