/* Trapola account dashboard — clean, Google-style, no external assets. */
:root {
  --blue: #0f766e;
  --blue-dark: #115e59;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --bg: #ffffff;
  --panel: #f8f9fa;
  --surface: #ffffff;
  --input-bg: #ffffff;
  --toast-bg: #202124;
  --toast-fg: #ffffff;
  --danger: #d93025;
  --danger-dark: #b3261e;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15);
}

/* Dark theme: the trapola.com look — deep navy (slate-950), slate-900
   surfaces, slate-800 borders, teal accent, soft ambient glow. */
[data-theme="dark"] {
  --blue: #2dd4bf;
  --blue-dark: #14b8a6;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #1e293b;
  --bg: #020617;
  --panel: #1e293b;
  --surface: #0f172a;
  --input-bg: #0f172a;
  --toast-bg: #334155;
  --toast-fg: #f1f5f9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .6), 0 2px 8px 2px rgba(0, 0, 0, .5);
}
/* Teal primary button on dark, like trapola.com's teal-on-navy pairing. */
[data-theme="dark"] .btn-primary { background: var(--blue-dark); color: #020617; }
[data-theme="dark"] .btn-primary:hover { background: #2dd4bf; }
/* Ambient glow behind everything, like trapola.com — subtle, dark only. */
[data-theme="dark"] body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px 400px at 50% -10%, rgba(20, 184, 166, .14), transparent 70%),
    radial-gradient(500px 350px at 85% 110%, rgba(99, 102, 241, .10), transparent 70%),
    radial-gradient(rgba(255, 255, 255, .03) 1px, transparent 1px);
  background-size: auto, auto, 24px 24px;
}
[data-theme="dark"] .notice { background: #3c2f10; border-color: #f9ab00; color: #f1f5f9; }
[data-theme="dark"] .pill { background: #1e293b; color: #2dd4bf; }
[data-theme="dark"] .status-active { background: #1e3a24; color: #81c995; }
[data-theme="dark"] .status-disabled { background: #3c1a18; color: #f28b82; }
[data-theme="dark"] .status-paused { background: #3c2f10; color: #fdd663; }

* { box-sizing: border-box; }

/* [hidden] must win over every display rule below (modal, MFA field, …):
   without this, CSS `display` overrides the attribute and the element
   stays visible. That was the grey veil over the whole page. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 24px; font-weight: 400; margin: 0 0 4px; }
h2 { font-size: 18px; font-weight: 500; margin: 0 0 8px; }
h3 { font-size: 15px; font-weight: 500; margin: 0 0 2px; }
p { margin: 0 0 8px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; font-size: 15px; }

.sub { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.fineprint { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }

.topbar-search { flex: 1; max-width: 560px; margin: 0 auto; }
.topbar-search input {
  width: 100%; height: 44px; padding: 0 16px 0 40px;
  border: 1px solid transparent; border-radius: 24px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='18' height='18'%3E%3Cpath fill='%235f6368' d='M15.5 14h-.79l-.28-.27a6.5 6.5 0 1 0-.7.7l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0A4.5 4.5 0 1 1 14 9.5 4.5 4.5 0 0 1 9.5 14z'/%3E%3C/svg%3E") no-repeat 12px center;
  outline: none;
}
.topbar-search input:focus { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; position: relative; }
.icon-btn { background: none; border: none; padding: 8px; border-radius: 50%; line-height: 0; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--panel); }
#theme-btn .icon-sun { display: none; }
[data-theme="dark"] #theme-btn .icon-sun { display: block; }
[data-theme="dark"] #theme-btn .icon-moon { display: none; }
.header-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); border-radius: 24px; padding: 8px 14px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; white-space: nowrap; }
.header-btn:hover { background: var(--panel); }
@media (max-width: 640px) { .header-btn span { display: none; } .header-btn { padding: 8px; border-radius: 50%; border: none; } }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--blue); color: #fff; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.avatar.big { width: 64px; height: 64px; font-size: 24px; }

.menu {
  position: absolute; top: 48px; right: 0; min-width: 240px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px; z-index: 30;
}
.menu a, .menu button.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: none; background: none; text-align: left;
  color: var(--ink); font-size: 14px; border-radius: 6px;
}
.menu a:hover, .menu button.menu-item:hover { background: var(--panel); text-decoration: none; }
.menu .menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .menu-head strong { display: block; font-size: 15px; }
.menu .menu-head span { color: var(--muted); font-size: 13px; }
.menu-sep { border-top: 1px solid var(--line); margin: 6px 0; }
.menu .app-dot { width: 28px; height: 28px; border-radius: 8px; color: #fff; font-weight: 700; font-size: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---------- layout ---------- */
main { min-height: calc(100vh - 120px); }
.wrap { max-width: 960px; margin: 0 auto; padding: 32px 16px; }
.wrap.narrow { max-width: 720px; }
.greeting { font-size: 28px; }
.section-title { margin: 28px 0 12px; font-size: 18px; }
.empty-note { color: var(--muted); }

/* ---------- auth card ---------- */
.auth-card {
  max-width: 450px; margin: 48px auto; padding: 36px 40px 28px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.auth-card h1 { text-align: center; }
.auth-card .sub { text-align: center; margin-bottom: 24px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 16px; }
.auth-logo-img { width: 180px; height: auto; }
.boot { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--muted); }
.boot img { width: 160px; max-width: 70%; height: auto; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; height: 46px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 4px; outline: none; background: var(--input-bg); color: var(--ink);
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.field textarea {
  width: 100%; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: 4px; outline: none; background: var(--input-bg); color: var(--ink);
  font: inherit; font-size: 15px;
}
.field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
input[type="date"] { color-scheme: light; }
[data-theme="dark"] input[type="date"] { color-scheme: dark; }
.form-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 8px; }
.notice { background: #fef7e0; border: 1px solid #f9ab00; border-radius: var(--radius); padding: 12px; margin: 16px 0; }

.btn {
  border: none; border-radius: 24px; padding: 10px 24px;
  font-size: 14px; font-weight: 500; background: var(--panel); color: var(--blue);
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #99f6e4; cursor: wait; }
.btn-outline { background: var(--surface); border: 1px solid var(--line); color: var(--blue); }
.btn-outline:hover { background: var(--panel); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-danger-outline { background: var(--surface); border: 1px solid var(--danger); color: var(--danger); }
.link-btn { background: none; border: none; color: var(--blue); font-size: 14px; padding: 4px 0; }
.link-btn:hover { text-decoration: underline; }

.tenant-list { display: grid; gap: 8px; margin-top: 12px; }
.tenant-list button {
  text-align: left; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); font-size: 15px;
}
.tenant-list button:hover { border-color: var(--blue); background: var(--panel); }

/* ---------- app grid ---------- */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.app-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 20px 16px;
  background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow .15s ease;
}
a.app-card:hover { text-decoration: none; box-shadow: var(--shadow); }
.app-card.disabled { opacity: .75; }
.app-icon {
  width: 48px; height: 48px; border-radius: 12px; color: #fff;
  font-weight: 700; font-size: 17px; display: flex; align-items: center; justify-content: center;
}
.app-shot {
  width: 100%; aspect-ratio: 16 / 10; object-fit: cover; object-position: top center;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
}
.app-card h3 { font-size: 16px; }
.app-card p { color: var(--muted); font-size: 13px; flex: 1; }
.app-open { color: var(--blue); font-size: 14px; font-weight: 500; }
.pill {
  display: inline-block; background: #ccfbf1; color: var(--blue);
  font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 12px;
  vertical-align: middle;
}

/* ---------- account panels ---------- */
.panel { border: 1px solid var(--line); border-radius: 12px; padding: 24px; margin-bottom: 20px; }
.panel.danger { border-color: #f2b8b5; }
.panel-head { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
.row-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: 16px 0; border-top: 1px solid var(--line);
}
.row-item:first-of-type { border-top: none; }
.row-item .btn { flex-shrink: 0; }
.inline-form { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }
.inline-form .btn { margin-top: 4px; }

/* ---------- modal / toast / footer ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(32, 33, 36, .5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal { background: var(--surface); border-radius: 12px; padding: 24px; max-width: 440px; width: 100%; box-shadow: var(--shadow); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-fg); padding: 12px 20px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 60; font-size: 14px; max-width: 90vw;
}
.footer {
  display: flex; justify-content: space-between; max-width: 960px;
  margin: 0 auto; padding: 16px; color: var(--muted); font-size: 13px;
  border-top: 1px solid var(--line);
}

/* ---------- admin ---------- */
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.tenant-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tenant-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--surface); }
.tenant-card.selected { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.tenant-card h3 { margin-bottom: 2px; }
.tenant-card .muted { font-size: 13px; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
.user-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.user-table th, .user-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.user-table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.user-table .btn { padding: 6px 12px; font-size: 13px; margin-right: 4px; }
.status-pill { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.status-active { background: #e6f4ea; color: #137333; }
.status-disabled { background: #fce8e6; color: #a50e0e; }
.status-paused { background: #fef7e0; color: #b06000; }
select { width: 100%; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--input-bg); color: var(--ink); font-size: 15px; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .auth-card { margin: 24px 12px; padding: 28px 20px; border: none; }
  .wrap { padding: 24px 16px; }
  .topbar-search { display: none; }
  .row-item { flex-direction: column; }
  .row-item .btn { align-self: flex-start; }
  .panel { padding: 18px; }
}

/* ---------- access control (v9) ---------- */
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 8px; cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--blue); flex-shrink: 0; }
.check-grid { display: grid; gap: 4px; margin: 4px 0 12px; }
.policy-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.policy-form .btn { grid-column: 1 / -1; justify-self: start; }
.admin-row-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: flex-start; }
.admin-row-actions .btn { padding: 6px 12px; font-size: 13px; }
.status-blocked { background: #fce8e6; color: #a50e0e; }
[data-theme="dark"] .status-blocked { background: #3c1a18; color: #f28b82; }
.app-card .btn { align-self: flex-start; margin-top: 4px; }

/* Admin per-user access panel (v10): click a user row, a panel opens
   under it with one table of every SaaS app. */
tr.clickable { cursor: pointer; }
.user-panel-row > td { background: var(--panel); padding: 16px 12px; white-space: normal; }
.access-summary { font-weight: 600; margin: 2px 0 10px; }
.access-table td { white-space: normal; vertical-align: middle; }
.access-table .app-dot { display: inline-flex; width: 28px; height: 28px; border-radius: 8px; color: #fff; font-weight: 700; font-size: 12px; align-items: center; justify-content: center; vertical-align: middle; margin-right: 8px; }
.status-none { background: #f1f5f9; color: #64748b; }
[data-theme="dark"] .status-none { background: #1e293b; color: #94a3b8; }
.user-panel-row .field { margin-top: 12px; }

/* ---------- usage & limits (v14) ---------- */
.limit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin: 12px 0 4px; }
.limit-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--surface); }
.limit-num { font-size: 28px; font-weight: 600; line-height: 1.2; }
.limit-unit { font-size: 14px; color: var(--muted); font-weight: 400; }
.limit-card h3 { margin-top: 6px; }
.limit-card p { color: var(--muted); font-size: 13px; }
#usage-mine h3 { margin-top: 16px; }
#usage-mine-body h3:first-child { margin-top: 0; }
