:root {
  --blue:       #1f4f8b;   /* Pilar primary (matches the logo) */
  --blue-dark:  #163a66;
  --blue-soft:  #e8f0fb;
  --bg:         #f4f6f9;
  --surface:    #ffffff;
  --border:     #dde3ea;
  --text:       #1b2430;
  --muted:      #637085;
  --ok:         #1f8b5f;
  --warn:       #b4690e;
  --danger:     #c0392b;
  --radius:     10px;
  --shadow:     0 1px 3px rgba(20,30,50,.08), 0 1px 2px rgba(20,30,50,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue:#5c9ae0; --blue-dark:#8fbdf0; --blue-soft:#17283f;
    --bg:#0f1621; --surface:#161f2b; --border:#28323f; --text:#e7edf5; --muted:#9aa7b8;
    --shadow:0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; cursor: pointer; }

/* ─── Top bar ─── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand-logo { height: 30px; width: auto; border-radius: 5px; display: block; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .3px; color: var(--blue-dark); }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 38px; height: 38px; border-radius: 9px; font-size: 18px; display: none;
}
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.lang-btn { border: 0; background: var(--surface); color: var(--muted); padding: 7px 11px; font-size: 13px; font-weight: 600; }
.lang-btn.active { background: var(--blue); color: #fff; }

/* ─── Layout ─── */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: 0; background: transparent; color: var(--text);
  padding: 10px 12px; border-radius: 9px; text-align: left; font-size: 14.5px; font-weight: 500;
}
.nav-item:hover { background: var(--blue-soft); }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .8; }
.main { padding: 20px; min-width: 0; }

/* ─── Screen (list) ─── */
.screen-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.screen-title { font-size: 21px; font-weight: 700; margin: 0; }
.screen-head .spacer { flex: 1; }
.search-box {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 9px 12px; font-size: 14px; min-width: 210px;
}
.search-box:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.btn {
  border: 1px solid var(--blue); background: var(--blue); color: #fff;
  border-radius: 9px; padding: 9px 14px; font-size: 14px; font-weight: 600;
}
.btn.secondary { background: var(--surface); color: var(--blue); }
.count-note { color: var(--muted); font-size: 13px; }

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

/* desktop table */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { background: var(--blue-soft); color: var(--blue-dark); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; text-align: left; }
table.grid td.right, table.grid th.right { text-align: right; }
table.grid td.center, table.grid th.center { text-align: center; }
table.grid tbody tr:hover { background: var(--blue-soft); cursor: pointer; }
table.grid tbody tr:last-child td { border-bottom: 0; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.s-0   { background: #eef1f5; color: #566; }
.pill.s-1   { background: #e4f0ff; color: #1f4f8b; }
.pill.s-10  { background: #e3f6ec; color: #1f8b5f; }
.pill.s-255 { background: #fdebea; color: #c0392b; }

/* mobile cards */
.cards { display: none; flex-direction: column; }
.rec-card { padding: 13px 14px; border-bottom: 1px solid var(--border); }
.rec-card:last-child { border-bottom: 0; }
.rec-card:active { background: var(--blue-soft); }
.rec-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.rec-key { font-weight: 700; font-size: 15px; }
.rec-amt { font-weight: 700; }
.rec-sub { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; justify-content: space-between; gap: 10px; }

.msg { padding: 28px; text-align: center; color: var(--muted); }
.msg.error { color: var(--danger); }

/* ─── User area / sign-in ─── */
.user-area { display: inline-flex; align-items: center; gap: 10px; }
.user-name { font-size: 13.5px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 11px; font-size: 13px; }
.logout-btn:hover { background: var(--blue-soft); }

body.signed-out .layout { display: none; }
.signin { position: fixed; inset: 56px 0 0 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.signin-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 34px 30px; width: 100%; max-width: 380px; text-align: center; }
.signin-logo { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; }
.signin-title { font-size: 26px; font-weight: 800; color: var(--blue-dark); margin-top: 12px; letter-spacing: .3px; }
.signin-tag { color: var(--muted); font-size: 14px; margin-top: 2px; }
.signin-msg { margin: 16px 0 4px; padding: 10px 12px; background: var(--blue-soft); color: var(--blue-dark); border-radius: 9px; font-size: 13.5px; }
.signin-google { display: block; margin-top: 20px; padding: 12px; font-size: 15px; text-decoration: none; text-align: center; }
.signin-invite { margin-top: 18px; text-align: left; display: none; }
.signin-invite.open { display: block; }
.invite-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.invite-row { display: flex; gap: 8px; }
.invite-row .search-box { flex: 1; min-width: 0; text-transform: uppercase; }

/* device gate */
.device-text { color: var(--text); font-size: 14px; margin: 14px 0 6px; }
.device-name { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }
.signin-card .btn { display: block; width: 100%; margin-top: 10px; text-align: center; }

/* modal (admin device management) */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,16,24,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 540px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.close-x { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
.close-x:hover { background: var(--blue-soft); }
.device-list { overflow-y: auto; padding: 6px 0; }
.device-row { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.device-row:last-child { border-bottom: 0; }
.device-info { flex: 1; min-width: 0; }
.device-user { font-weight: 600; font-size: 14px; }
.device-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.dev-status { font-weight: 600; }
.dev-status.s-approved { color: var(--ok); }
.dev-status.s-pending { color: var(--warn); }
.dev-status.s-revoked { color: var(--danger); }
.device-actions { display: flex; gap: 6px; flex: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* ─── Toast ─── */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--blue-dark); color: #fff; padding: 11px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; z-index: 50; max-width: 90vw;
}

/* ─── Responsive ─── */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; width: 230px; z-index: 30;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .main { padding: 14px; }
  table.grid { display: none; }
  .cards { display: flex; }
  .search-box { flex: 1; min-width: 0; }
}
