:root {
  --primary: #0077C8;
  --primary-dark: #000000;
  --accent: #00AEEF;
  --light: #F4F7FB;
  --success: #1B8A5A;
  --danger: #C0392B;
  --text: #132238;
  --muted: #5B6B7C;
  --border: #D7E0EA;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Outfit", "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(0, 174, 239, 0.12), transparent 55%),
    linear-gradient(160deg, #eef3f9 0%, var(--light) 45%, #e8eef6 100%);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #000 0%, #001018 55%, #003a66 100%);
  color: #fff;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand-logo { width: 48px; height: 48px; }
.brand-logo-full { width: min(100%, 180px); height: auto; display: block; }
.guest-logo-full {
  width: min(100%, 260px);
  height: auto;
  display: block;
  margin: 0 auto 1.25rem;
}
.brand strong { font-family: var(--display); font-size: 1.15rem; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.nav a {
  color: rgba(255,255,255,.88);
  padding: .65rem .8rem;
  border-radius: 10px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.nav a i { width: 1.15rem; text-align: center; opacity: .95; color: var(--accent); }
.nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.sidebar-foot { margin-top: auto; }
.user-chip {
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .65rem;
}
.user-chip-link { color: inherit; text-decoration: none; }
.user-chip-link:hover { text-decoration: none; opacity: .9; }
.user-chip small { display: block; opacity: .7; }
.btn-logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,.45);
  color: #fff !important;
}
.btn-logout:hover {
  background: rgba(255,255,255,.12);
  text-decoration: none;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #111;
  border: 2px solid rgba(0,174,239,.45);
}
.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 72px; height: 72px; }
.profile-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.profile-head h2 { margin: 0; font-family: var(--display); }
.profile-panel { max-width: 520px; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 {
  font-family: var(--display);
  font-size: 1.25rem;
  margin: 0;
  flex: 1;
}
.topbar-brand-mobile { display: none; }
.topbar-icon { width: 32px; height: 32px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: .85rem; }
.topbar-user {
  display: flex; align-items: center; gap: .55rem;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.topbar-user:hover { text-decoration: none; opacity: .85; }
.topbar-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; border: 0; background: transparent; font-size: 1.25rem; cursor: pointer; color: var(--primary); }
.phone { font-weight: 600; color: var(--primary); white-space: nowrap; }
.app-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 1.35rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .88rem;
  background: rgba(255,255,255,.55);
}
.app-footer p { margin: 0; }
.app-footer a { color: var(--primary); font-weight: 600; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.content { padding: 1.25rem; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card span { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.stat-card strong { font-family: var(--display); font-size: 1.45rem; }
.stat-card.accent { background: linear-gradient(135deg, #0054A6, var(--accent)); color: #fff; border: 0; }
.stat-card.accent span { color: rgba(255,255,255,.8); }

.panel-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 1rem; }
.panel, .form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.panel h2, .panel h3 { font-family: var(--display); margin-top: 0; }
.map { height: 280px; border-radius: 12px; overflow: hidden; background: #dce5f0; }

.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-width: 100%;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem .9rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; word-break: break-word; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8fbff; }
.btn-sm { padding: .4rem .7rem; font-size: .85rem; border-radius: 10px; }
.empty-row { text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px; padding: .65rem 1rem;
  font-weight: 600; cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); text-decoration: none; }
.btn-accent { background: var(--accent); color: #1a1200; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-block { width: 100%; }

.stack { display: flex; flex-direction: column; gap: .85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.row-inline { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 500; font-size: .92rem; }
input, select, textarea {
  font: inherit; padding: .7rem .8rem; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
.check { flex-direction: row; align-items: center; gap: .5rem; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.list { padding-left: 1.1rem; }
.thumbs { display: flex; flex-wrap: wrap; gap: .75rem; }
.badge {
  display: inline-block; padding: .2rem .55rem; border-radius: 999px;
  background: #e8eef8; color: var(--primary); font-size: .78rem; font-weight: 600;
}
.badge-closed, .badge-rejected { background: #fde8e6; color: var(--danger); }
.badge-in_progress, .badge-approved { background: #e6f6ee; color: var(--success); }
.badge-pending_close, .badge-awaiting_approval, .badge-draft { background: #fff4e0; color: #9a6200; }

.alert { padding: .85rem 1rem; border-radius: 12px; margin: .75rem 1.25rem 0; }
.alert-success { background: #e6f6ee; color: #145c3c; }
.alert-error { background: #fde8e6; color: #8a241c; }
.content .alert { margin: 0 0 1rem; }

.guest-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(0,174,239,.25), transparent 60%),
    linear-gradient(160deg, #0a0a0a 0%, #001828 100%);
}
.guest-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid #e6eef5;
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  text-align: center;
  color: var(--text);
}
.guest-card .muted { color: var(--muted); }
.guest-card label { color: var(--text); }
.guest-card input, .guest-card select, .guest-card textarea {
  background: #fff; border-color: var(--border); color: var(--text);
}
.guest-card form { text-align: left; }
.guest-card .alert { text-align: left; }
.guest-card .secret {
  background: #f4f7fb; border-color: var(--border); color: var(--primary);
}
.totp-box { margin: 1rem 0; }
.totp-box .qr {
  background: #fff; border-radius: 12px; padding: .5rem;
  display: inline-block;
}
.secret {
  display: block; word-break: break-all; background: #111;
  border: 1px solid #333; border-radius: 8px; padding: .6rem; color: var(--accent);
}
.setup-steps { text-align: left; color: #c5ced6; padding-left: 1.2rem; font-size: .92rem; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 35;
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; width: 100%; max-width: 100vw; }
  .main { max-width: 100vw; overflow-x: hidden; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw);
    transform: translateX(-105%); transition: transform .25s ease; z-index: 40;
    height: 100%; max-height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop[hidden] { display: none !important; }
  .sidebar-backdrop:not([hidden]) { display: block; }
  .menu-toggle { display: inline-flex; flex-shrink: 0; padding: .35rem; }
  .topbar {
    gap: .45rem;
    padding: .7rem .75rem;
    padding-right: max(.75rem, env(safe-area-inset-right));
  }
  .topbar-brand-mobile { display: block; flex-shrink: 0; }
  .topbar-icon { width: 28px; height: 28px; }
  .topbar h1 {
    font-size: 1.05rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-right { gap: .45rem; flex-shrink: 0; }
  .topbar-user-name { display: none; }
  .phone-text { display: none; }
  .phone {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: #eef6fc;
  }
  .avatar-header { width: 34px; height: 34px; }
  .content { padding: .85rem; max-width: 100%; }
  .toolbar .btn { width: 100%; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; }
  .content .alert { margin: 0 0 .85rem; }
  .alert { margin: .65rem .75rem 0; }
  .panel, .form-card { padding: .9rem; }
  .panel-grid, .grid-2 { grid-template-columns: 1fr; }
  .cards-grid { grid-template-columns: 1fr 1fr; gap: .65rem; }
  .stat-card strong { font-size: 1.15rem; }
  .map { height: 220px; }
  .app-footer { font-size: .75rem; text-align: center; padding: .85rem; line-height: 1.45; }
  .row-inline { flex-direction: column; align-items: stretch; }
  .row-inline > * { width: 100%; }

  /* Tabelas → cartões no telemóvel */
  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  .responsive-table { min-width: 0 !important; }
  .responsive-table thead { display: none; }
  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    margin-bottom: .75rem;
    padding: .35rem .15rem;
  }
  .responsive-table td {
    display: grid;
    grid-template-columns: 38% 1fr;
    gap: .5rem;
    padding: .55rem .85rem;
    border-bottom: 1px solid #eef2f6;
    text-align: left;
  }
  .responsive-table td:last-child { border-bottom: 0; }
  .responsive-table td::before {
    content: attr(data-label);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    align-self: start;
    padding-top: .15rem;
  }
  .responsive-table td[data-label=""] {
    grid-template-columns: 1fr;
  }
  .responsive-table td[data-label=""]::before { display: none; }
  .responsive-table td.empty-row,
  .responsive-table td[colspan] {
    display: block;
    text-align: center;
    grid-template-columns: 1fr;
  }
  .responsive-table td[colspan]::before { display: none; }
}

@media (max-width: 420px) {
  .cards-grid { grid-template-columns: 1fr; }
  .topbar-brand-mobile { display: none; }
}
