/* InovaShare - estilos partilhados (login + painel) */
:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --fg: #111111;
  --muted: #6b6b68;
  --line: #e4e4df;
  --ink: #111111;          /* cor da marca: o preto do logo */
  --ink-fg: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --chart: #111111;
  --chart-2: #9a9a95;
  --logo-filter: none;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --radius: 16px;
  --brand-bg: linear-gradient(180deg, #e4e7ee 0%, #c9cfdc 100%);
  --brand-fg: #111111;
  --brand-p: #4a4d55;
  --brand-small: #6b6e76;
  --brand-veil: 240, 242, 246;
  --brand-veil-top: .92;
  --brand-veil-bottom: .96;
  --brand-img-filter: none;
  --knob: #ffffff;
  color-scheme: light;
}

/* escuro: escolhido no botão, ou do sistema se não houver escolha guardada */
:root[data-theme="dark"] {
  --bg: #0b0b0c;
  --surface: #151517;
  --surface-2: #1c1c1f;
  --fg: #f2f2f0;
  --muted: #9b9b97;
  --line: #26262a;
  --ink: #f2f2f0;
  --ink-fg: #0b0b0c;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #f87171;
  --chart: #f2f2f0;
  --chart-2: #6b6b68;
  --logo-filter: invert(1);
  --shadow: none;
  --brand-bg: #0b0b0c;
  --brand-fg: #f2f2f0;
  --brand-p: #b5b5b0;
  --brand-small: #8a8a86;
  --brand-veil: 11, 11, 12;
  --brand-veil-top: .85;
  --brand-veil-bottom: .95;
  --brand-img-filter: brightness(.8) saturate(1.1);
  --knob: #3a3a40;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c;
    --surface: #151517;
    --surface-2: #1c1c1f;
    --fg: #f2f2f0;
    --muted: #9b9b97;
    --line: #26262a;
    --ink: #f2f2f0;
    --ink-fg: #0b0b0c;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #f87171;
    --chart: #f2f2f0;
    --chart-2: #6b6b68;
    --logo-filter: invert(1);
    --shadow: none;
    --brand-bg: #0b0b0c;
    --brand-fg: #f2f2f0;
    --brand-p: #b5b5b0;
    --brand-small: #8a8a86;
    --brand-veil: 11, 11, 12;
    --brand-veil-top: .85;
    --brand-veil-bottom: .95;
    --brand-img-filter: brightness(.8) saturate(1.1);
    --knob: #3a3a40;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.logo { display: block; filter: var(--logo-filter); }

.wordmark {
  font-weight: 700;
  letter-spacing: .02em;
}
.wordmark span { font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--ink-fg);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--line);
}
.btn.small { padding: 7px 12px; font-size: 13px; }

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

.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.login-brand {
  position: relative;
  overflow: hidden;
  background: var(--brand-bg);
  color: var(--brand-fg);
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
/* imagem a ocupar o painel, com véus em cima e em baixo para o logo e o texto */
.login-brand .hero, .login-brand .hero img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
.login-brand .hero img { object-fit: cover; object-position: 50% 45%; filter: var(--brand-img-filter); }
.login-brand::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(var(--brand-veil), var(--brand-veil-top)) 0%, rgba(var(--brand-veil), 0) 26%),
    linear-gradient(0deg, rgba(var(--brand-veil), var(--brand-veil-bottom)) 0%, rgba(var(--brand-veil), .72) 23%, rgba(var(--brand-veil), 0) 44%);
}
.login-brand > :not(.hero) { position: relative; z-index: 1; }
.login-brand .logo { width: 140px; filter: var(--logo-filter); }
.login-brand h2 {
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 1.1;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -.01em;
}
.login-brand p { margin: 0; color: var(--brand-p); max-width: 34ch; font-weight: 500; }
.login-brand small { color: var(--brand-small); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.login-brand > div { margin-top: auto; margin-bottom: 20px; }

.login-form {
  display: grid;
  place-items: center;
  padding: 48px 16px;
}
.login-form form { width: 100%; max-width: 360px; }
.login-form .logo-mobile { display: none; width: 96px; margin-bottom: 28px; }
.login-form h1 { margin: 0 0 6px; font-size: 26px; font-weight: 700; }
.login-form .sub { margin: 0 0 32px; color: var(--muted); }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent);
}
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 76px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 8px;
}
.pw-toggle:hover { color: var(--fg); }

.login-form .btn { width: 100%; margin-top: 8px; padding: 14px; }

.alert {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bad) 10%, transparent);
  color: var(--bad);
  font-size: 14px;
  font-weight: 500;
}
.alert.show { display: block; }

@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { min-height: 190px; padding: 0; }
  .login-brand::after { background: linear-gradient(0deg, var(--bg) 0%, transparent 45%); }
  .login-brand > :not(.hero) { display: none; }
  .login-brand .hero img { object-position: 50% 40%; filter: none; }
  .login-form { align-items: start; padding-top: 8px; }
  .login-form .logo-mobile { display: block; }
}

/* ---------- Painel ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; gap: 16px;
}
.topbar .logo { height: 30px; width: auto; }
.topbar .divider { width: 1px; height: 24px; background: var(--line); }
.topbar .wordmark { font-size: 17px; }
.topbar .spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  background: var(--surface);
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

main { max-width: 1200px; margin: 0 auto; padding: 32px 24px 48px; }

.hello { margin-bottom: 28px; }
.hello h1 { margin: 0 0 4px; font-size: clamp(24px, 3vw, 32px); font-weight: 700; letter-spacing: -.01em; }
.hello p { margin: 0; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.span-2 { grid-column: span 2; }
.span-4 { grid-column: 1 / -1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 12px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}
.card-badge { font-size: 12px; font-weight: 600; color: var(--muted); }
.card-badge.warn { color: var(--warn); }
.card-badge.bad { color: var(--bad); }
.card-badge.ok { color: var(--ok); }

.big {
  font-size: 34px; font-weight: 700; line-height: 1.1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.big small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.meta { margin-top: 6px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.spark { display: block; width: 100%; height: 48px; margin-top: 14px; }
.spark path.line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark path.area { fill: var(--chart); opacity: .07; stroke: none; }
.spark path.line.alt { stroke: var(--chart-2); }

.bar {
  height: 8px; margin-top: 16px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.bar > i {
  display: block; height: 100%; width: 0;
  border-radius: inherit;
  background: var(--ink);
  transition: width .6s ease;
}
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

.net {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.net .label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.net .label i { width: 10px; height: 3px; border-radius: 2px; background: var(--chart); }
.net .label i.alt { background: var(--chart-2); }
.net .big { font-size: 26px; margin-top: 4px; }

.kv { margin: 0; display: grid; gap: 12px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.kv dd a { text-decoration: none; border-bottom: 1px solid var(--line); }
.kv dd a:hover { border-color: var(--fg); }

.services {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px;
}
.services li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.services .name { flex: 1; font-weight: 500; font-size: 14px; min-width: 0; }
.services .id { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.services .state { font-size: 12px; font-weight: 600; color: var(--muted); }

.foot {
  margin-top: 28px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 13px;
}

.skeleton { color: transparent !important; background: var(--surface-2); border-radius: 6px; }

@media (max-width: 1000px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar-inner { padding: 12px 16px; gap: 12px; }
  .topbar .wordmark, .topbar .divider { display: none; }
  main { padding: 24px 16px 40px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .big { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- App: navegação ---------- */

.brand { display: flex; align-items: center; gap: 16px; text-decoration: none; color: inherit; }

.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a {
  padding: 8px 12px; border-radius: 8px;
  text-decoration: none; color: var(--muted);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tabs a:hover { color: var(--fg); background: var(--surface-2); }
.tabs a.active { color: var(--fg); background: var(--surface-2); }
.tabs.mobile { display: none; }

.seg {
  display: inline-flex; padding: 3px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
.seg button {
  border: 0; background: none; cursor: pointer;
  padding: 5px 10px; border-radius: 7px;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--ink-fg); }

.account {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  text-decoration: none; color: var(--fg); font-size: 14px; font-weight: 500;
}
.account:hover, .account.active { background: var(--surface-2); }

.avatar {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--ink); color: var(--ink-fg);
  font-weight: 700; font-size: 13px;
}

.banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--warn) 14%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, var(--bg));
  font-size: 14px; text-align: center;
}
.link {
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; font-weight: 600; color: inherit; text-decoration: underline;
}

/* ---------- App: elementos comuns ---------- */

.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.ico {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.big-ico { width: 48px; height: 48px; margin-bottom: 8px; }

.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 34px; height: 34px; padding: 0; }

.toolbar input, .toolbar select, .new-user select, .users select, .pw-inline input {
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--fg);
  font: inherit; font-size: 14px;
}
.new-user select { width: 100%; padding: 13px 12px; font-size: 15px; }
.toolbar input:focus, select:focus, .pw-inline input:focus {
  outline: none; border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent);
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 { margin: 0 0 4px; font-size: clamp(24px, 3vw, 32px); font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin: 0; }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.narrow { max-width: 440px; }
.narrow .btn { margin-top: 4px; }

/* ---------- Caixa partilhada ---------- */

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; }
.search { position: relative; flex: 1; }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; padding-left: 40px; }

.files-card { padding: 0; overflow: hidden; }
.files .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px 130px 140px 84px;
  align-items: center; gap: 16px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
}
.files .row:not(.head):hover { background: var(--surface-2); }
.files .row.head {
  border-top: 0; padding-top: 16px; padding-bottom: 10px;
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.files .name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; text-decoration: none; min-width: 0; }
a.fname:hover { text-decoration: underline; }
.files .size, .files .owner, .files .date { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.files .actions { display: flex; justify-content: flex-end; gap: 6px; }
.files .actions .btn.danger { width: auto; padding: 0 10px; font-size: 12px; }
.no-results { padding: 20px; margin: 0; border-top: 1px solid var(--line); text-align: center; }

.ftype {
  --c: var(--muted);
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.ftype.img { --c: #8b5cf6; }
.ftype.doc { --c: #ef4444; }
.ftype.sheet { --c: #16a34a; }
.ftype.slide { --c: #ea580c; }
.ftype.video { --c: #0ea5e9; }
.ftype.audio { --c: #db2777; }
.ftype.zip { --c: #ca8a04; }

.empty { text-align: center; padding: 56px 16px; }
.empty svg { width: 64px; height: 64px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linejoin: round; }
.empty h3 { margin: 12px 0 4px; font-size: 18px; }
.empty p { margin: 0; }

.uploads { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.uploads:empty { display: none; }
.uploads li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.up-main { flex: 1; min-width: 0; }
.up-top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.up-top .pct { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.uploads .bar { margin-top: 8px; height: 6px; }
.uploads li.ok .bar > i { background: var(--ok); }
.uploads li.bad .pct { color: var(--bad); }

.drop-overlay {
  position: fixed; inset: 12px; z-index: 50;
  display: grid; place-items: center; text-align: center;
  border: 3px dashed var(--ink); border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  font-size: 18px; font-weight: 600;
  pointer-events: none;
}

/* ---------- Utilizadores ---------- */

.new-user { margin-bottom: 16px; }
.new-user .form-row {
  display: grid; grid-template-columns: 1fr 1fr 190px auto;
  gap: 16px; align-items: end;
}
.new-user .field { margin: 0; }
.new-user .btn { padding: 13px 22px; }

.created { margin-bottom: 16px; border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.created p { margin: 0; font-size: 14px; }
.created pre {
  margin: 12px 0; padding: 14px;
  background: var(--surface-2); border-radius: 10px;
  font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere;
}

.urow { padding: 14px 0; border-top: 1px solid var(--line); }
.urow:first-child { border-top: 0; padding-top: 0; }
.urow:last-child { padding-bottom: 0; }
.uline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.uname { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.uname .muted { font-size: 13px; }
.tag {
  margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 600; vertical-align: middle;
}
.uactions { display: flex; gap: 6px; }
.uactions .btn.danger { width: auto; padding: 0 10px; font-size: 12px; }
.pw-inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-left: 44px; }
.pw-inline input { flex: 1; min-width: 180px; }

/* ---------- Avisos ---------- */

.toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100;
  display: grid; gap: 8px; width: min(420px, calc(100% - 32px));
}
.toast {
  padding: 12px 16px; border-radius: 10px;
  background: var(--ink); color: var(--ink-fg);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transition: opacity .4s, transform .4s;
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- App: ecrãs pequenos ---------- */

@media (max-width: 900px) {
  .tabs:not(.mobile) { display: none; }
  .tabs.mobile { display: flex; margin: 0; padding: 0 16px 10px; overflow-x: auto; }
  .account-name { display: none; }
  .account { padding: 0; }
  .new-user .form-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  .files .row.head { display: none; }
  .files .row {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "name name name actions" "size owner date date";
    column-gap: 8px; row-gap: 0; padding: 12px 16px;
  }
  .files .name { grid-area: name; }
  .files .size { grid-area: size; padding-left: 50px; }
  .files .owner { grid-area: owner; }
  .files .date { grid-area: date; }
  .files .actions { grid-area: actions; }
  .files .size, .files .owner, .files .date { font-size: 12px; margin-top: -10px; }
  .files .owner::before, .files .date::before { content: "· "; }
  .files .row .name { padding-bottom: 6px; }
  .new-user .form-row { grid-template-columns: 1fr; }
  .page-head .btn { width: 100%; }
  .pw-inline { padding-left: 0; }
}

@media (max-width: 560px) {
  .seg button { padding: 5px 8px; font-size: 12px; }
}

/* ajustes */
.users select { width: 170px; }
.uactions { min-width: 150px; justify-content: flex-end; }
.search { min-width: 0; }
@media (max-width: 700px) {
  .files .row { column-gap: 4px; }
  .uactions { min-width: 0; }
  .users select { width: auto; }
}
@media (max-width: 560px) {
  .toolbar select { max-width: none; padding-right: 6px; }
}
.uline { display: grid; grid-template-columns: 30px minmax(0, 1fr) 170px 170px; }
.uactions { min-width: 0; }
@media (max-width: 700px) {
  .uline { grid-template-columns: 30px minmax(0, 1fr) auto; row-gap: 10px; }
  .uname { grid-column: 2 / 4; }
  .users select { grid-column: 2; width: 100%; }
  .uactions { grid-column: 3; }
}
@media (max-width: 700px) {
  .uactions .lbl { display: none; }
  .uactions .btn { width: 34px; height: 34px; padding: 0; }
}

/* ---------- Ao vivo ---------- */

.summary-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--ok);
}
.live .dot { width: 7px; height: 7px; background: var(--ok); animation: pulse 2s ease-in-out infinite; }
.live.off { color: var(--muted); }
.live.off .dot { background: var(--muted); animation: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 45%, transparent); }
  50% { box-shadow: 0 0 0 5px transparent; }
}

.files .row.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh {
  0%, 30% { background: color-mix(in srgb, var(--ok) 14%, transparent); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .live .dot, .files .row.fresh { animation: none; }
}

/* ---------- Interruptor claro / escuro ---------- */

.theme-toggle {
  position: relative; flex: none;
  width: 60px; height: 32px; padding: 0 9px;
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  cursor: pointer;
}
.theme-toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.theme-toggle > .ico { width: 13px; height: 13px; }
.theme-toggle .knob {
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--knob); color: var(--fg);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .25s ease;
}
.theme-toggle .knob .ico { width: 14px; height: 14px; }
.theme-toggle .k-moon { display: none; }

/* escuro: o botão desliza para a lua */
:root[data-theme="dark"] .theme-toggle .knob { transform: translateX(28px); }
:root[data-theme="dark"] .theme-toggle .k-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .k-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .knob { transform: translateX(28px); }
  :root:not([data-theme="light"]) .theme-toggle .k-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .k-moon { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .theme-toggle .knob { transition: none; }
}

.login-form { position: relative; }
.login-form .theme-toggle { position: absolute; top: 20px; right: 20px; }

.logout .ico { display: none; }
@media (max-width: 560px) {
  .topbar-inner { gap: 8px; }
  .topbar .logo { height: 26px; }
  .logout { width: 36px; height: 36px; padding: 0; }
  .logout .ico { display: block; }
  .logout .lbl { display: none; }
}

/* interruptor compacto no telemóvel */
@media (max-width: 560px) {
  .topbar .theme-toggle { width: 50px; height: 28px; padding: 0 7px; }
  .topbar .theme-toggle .knob { width: 20px; height: 20px; }
  .topbar .theme-toggle > .ico { width: 11px; height: 11px; }
  .topbar .theme-toggle .knob .ico { width: 12px; height: 12px; }
  :root[data-theme="dark"] .topbar .theme-toggle .knob { transform: translateX(22px); }
}
@media (max-width: 560px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .topbar .theme-toggle .knob { transform: translateX(22px); }
}

/* ---------- Pastas ---------- */

.ph-main { min-width: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  margin-bottom: 6px; font-size: 14px; color: var(--muted);
}
.crumbs .ico { width: 14px; height: 14px; }
.crumb {
  padding: 3px 6px; border-radius: 6px; border: 0; background: none;
  color: var(--muted); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
a.crumb:hover, button.crumb:hover { color: var(--fg); background: var(--surface-2); }
.crumb.current { color: var(--fg); font-weight: 600; cursor: default; }
.crumb.drop-target { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--fg); }

.ftype.folder { --c: #3b82f6; }
.ftype.folder .ico { width: 20px; height: 20px; fill: color-mix(in srgb, var(--c) 25%, transparent); }

.folder-row { cursor: pointer; }
.folder-row .fname { font-weight: 600; }
.files .row.drop-target { background: color-mix(in srgb, var(--ok) 14%, transparent); box-shadow: inset 0 0 0 2px var(--ok); }
.files .row.dragging { opacity: .45; }

.name-text { display: flex; flex-direction: column; min-width: 0; }
.where {
  font-size: 12px; color: var(--muted); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.where:hover { color: var(--fg); text-decoration: underline; }

.rename {
  flex: 1; min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--ink); border-radius: 8px;
  background: var(--surface); color: var(--fg);
  font: inherit; font-weight: 500;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent);
}
.rename:focus { outline: none; }
.new-folder .hint-cell { grid-column: 2 / -1; font-size: 13px; color: var(--muted); }

.ico-more { stroke-width: 3.2; }

/* menu de ações */
.files .actions { position: relative; }
.menu {
  position: fixed; z-index: 60;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.16);
  display: grid; gap: 2px;
}
.menu button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--fg);
  font: inherit; font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu .ico { width: 16px; height: 16px; color: var(--muted); }
.menu .danger-item { color: var(--bad); }
.menu .danger-item .ico { color: var(--bad); }
.menu .danger-item.armed { background: var(--bad); color: #fff; }
.menu .danger-item.armed .ico { color: #fff; }

/* painel mover */
.move-panel { margin-bottom: 16px; }
.tree { display: grid; gap: 2px; max-height: 320px; overflow: auto; margin: 0 -8px; }
.tree-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px 9px calc(10px + var(--d) * 20px);
  border: 0; border-radius: 8px; background: none; color: var(--fg);
  font: inherit; font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
}
.tree-item .ico { width: 18px; height: 18px; color: #3b82f6; }
.tree-item:hover:not(:disabled) { background: var(--surface-2); }
.tree-item.sel { background: var(--ink); color: var(--ink-fg); }
.tree-item.sel .ico { color: inherit; }
.tree-item:disabled { color: var(--muted); cursor: default; opacity: .6; }
.tree-item small { color: var(--muted); font-weight: 400; }
.move-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 900px) {
  .page-head { align-items: stretch; flex-direction: column; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
}
@media (max-width: 700px) {
  .head-actions .btn.ghost { flex: 1 1 40%; }
  .head-actions .btn:not(.ghost) { flex: 1 1 100%; }
  .new-folder .hint-cell { display: none; }
  .files .row.new-folder { grid-template-areas: "name name name name"; }
}
@media (max-width: 700px) {
  .page-head .head-actions .btn { width: auto; }
}
@media (max-width: 700px) {
  .head-actions .btn { padding: 12px 10px; gap: 6px; font-size: 14px; }
}

/* ---------- Pré-visualização ---------- */

.file-row { cursor: pointer; }
body.viewer-open { overflow: hidden; }

.viewer {
  position: fixed; inset: 0; z-index: 80;
  display: flex; flex-direction: column;
  background: rgba(10, 10, 12, .94);
  color: #f2f2f0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: v-in .15s ease-out;
}
@keyframes v-in { from { opacity: 0; } to { opacity: 1; } }

.viewer-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.vb-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.vb-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.vb-title span { font-size: 13px; color: #9b9b97; }
.viewer .v-download { background: #f2f2f0; color: #0b0b0c; border-color: #f2f2f0; }
.v-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: rgba(255,255,255,.1); color: #f2f2f0; cursor: pointer;
}
.v-btn:hover { background: rgba(255,255,255,.18); }
.viewer :focus-visible { outline: 2px solid #f2f2f0; outline-offset: 2px; }

.viewer-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 20px 72px;
  overflow: auto;
}
.v-img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 6px;
  cursor: zoom-in;
  background: repeating-conic-gradient(#e9e9e6 0 25%, #ffffff 0 50%) 50% / 20px 20px; /* xadrez claro para imagens transparentes */
}
.v-img.zoom { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-body:has(.v-img.zoom) { justify-content: flex-start; align-items: flex-start; }
.v-pdf { width: min(1100px, 100%); height: 100%; border: 0; border-radius: 8px; background: #fff; }
.v-video { max-width: 100%; max-height: 100%; border-radius: 8px; background: #000; }

.viewer-text, .viewer-table {
  width: min(1100px, 100%); flex: 1; min-height: 0;
  margin: 0; overflow: auto;
  background: #151517; border: 1px solid #26262a; border-radius: 10px;
}
.viewer-text {
  padding: 20px;
  font: 13px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere; color: #e6e6e3;
}
.viewer-table table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.viewer-table th, .viewer-table td { padding: 8px 12px; border-bottom: 1px solid #26262a; text-align: left; white-space: nowrap; }
.viewer-table th { position: sticky; top: 0; background: #1c1c1f; font-weight: 600; }
.viewer-table tr:hover td { background: #1c1c1f; }
.v-note { margin: 0; font-size: 13px; color: #9b9b97; }
.v-loading { color: #9b9b97; }

.v-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 36px 28px; max-width: 420px; width: 100%;
  background: #151517; border: 1px solid #26262a; border-radius: 16px;
}
.v-card b { font-size: 16px; overflow-wrap: anywhere; }
.v-card p { margin: 0; color: #9b9b97; font-size: 14px; }
.v-card audio { width: 100%; margin-top: 4px; }
.v-card .btn { margin-top: 6px; background: #f2f2f0; color: #0b0b0c; border-color: #f2f2f0; }
.ftype.big { width: 72px; height: 72px; border-radius: 16px; font-size: 15px; }

.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: rgba(255,255,255,.1); color: #f2f2f0; cursor: pointer;
}
.v-nav:hover { background: rgba(255,255,255,.2); }
.v-nav.prev { left: 14px; }
.v-nav.prev .ico { transform: rotate(180deg); }
.v-nav.next { right: 14px; }

@media (max-width: 700px) {
  .viewer-bar { padding: 10px 12px; gap: 10px; }
  .viewer .v-download { width: 38px; height: 38px; padding: 0; }
  .viewer .v-download .lbl { display: none; }
  .viewer-body { padding: 12px 12px 76px; }
  .v-nav { top: auto; bottom: 14px; transform: none; }
  .v-nav.prev { left: calc(50% - 56px); }
  .v-nav.next { right: calc(50% - 56px); }
}
@media (prefers-reduced-motion: reduce) { .viewer { animation: none; } }

.viewer-table { flex: 0 1 auto; }

/* ---------- Ícones da app ---------- */

.ficon { width: 38px; height: 38px; flex: none; object-fit: contain; }
.ficon.sm { width: 20px; height: 20px; }
.ficon.big { width: 84px; height: 84px; }
.empty-ico { width: 96px; height: 96px; object-fit: contain; }
.uploads .ficon { width: 32px; height: 32px; }
.viewer-bar .ficon { width: 34px; height: 34px; }
.crumb.root { display: inline-flex; align-items: center; gap: 6px; }
.tree-item .ficon.sm { width: 22px; height: 22px; }

/* telemóvel: o ícone ocupa uma coluna própria, centrado nas duas linhas (nome + detalhes) */
@media (max-width: 700px) {
  .files .row {
    grid-template-columns: 50px auto auto minmax(0, 1fr) auto;
    grid-template-areas: "ico name name name actions" "ico size owner date actions";
    row-gap: 2px; align-items: center;
  }
  .files .row .name { display: contents; }
  .files .row .name > .ficon { grid-area: ico; align-self: center; }
  .files .row .name > :not(.ficon) { grid-area: name; min-width: 0; }
  .files .size { padding-left: 0; }
  .files .size, .files .owner, .files .date { margin-top: 0; }
  .files .actions { align-self: center; }
  .files .row.new-folder { grid-template-areas: "ico name name name name"; }
}
