:root {
  color-scheme: light;
  --primary: var(--tenant-primary, #123a63);
  --primary-strong: #0b2a49;
  --secondary: var(--tenant-secondary, #25a778);
  --background: #f4f7fa;
  --surface: #ffffff;
  --surface-muted: #edf2f6;
  --text: #172635;
  --muted: #657688;
  --border: #d8e1e8;
  --success: #137a57;
  --warning: #a46108;
  --danger: #ba3131;
  --sidebar: #102f50;
  --shadow: 0 8px 30px rgba(19, 42, 65, .08);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--background); }
body { margin: 0; overflow-x: hidden; color: var(--text); background: var(--background); font-size: 1rem; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
a { color: var(--primary); }
img { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(37, 167, 120, .35); outline-offset: 2px; }

.shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 268px; z-index: 40; display: flex; flex-direction: column; padding: 24px 18px; color: #fff; background: var(--sidebar); transform: translateX(-100%); transition: transform .2s ease; }
.sidebar.is-open { transform: translateX(0); }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; font-weight: 760; letter-spacing: -.02em; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #fff; color: var(--primary); font-weight: 850; }
.brand-logo { width: 52px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; padding: 4px; border-radius: 10px; background: rgba(255,255,255,.12); }
.brand-logo img { max-width: 100%; max-height: 34px; object-fit: contain; }
.brand small { display: block; color: #b8c9d8; font-size: .75rem; font-weight: 550; letter-spacing: .04em; text-transform: uppercase; }
.nav { display: grid; gap: 7px; margin-top: 34px; }
.nav a { min-height: 46px; display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: #cfdae4; border-radius: 10px; text-decoration: none; font-size: .94rem; font-weight: 620; }
.nav a:hover, .nav a.is-active { color: #fff; background: rgba(255,255,255,.11); }
.nav-icon { width: 22px; text-align: center; font-size: 1.05rem; }
.sidebar-foot { margin-top: auto; padding: 16px 12px 0; border-top: 1px solid rgba(255,255,255,.12); color: #b8c9d8; font-size: .82rem; }
.sidebar-foot strong { display: block; color: #fff; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backdrop { position: fixed; inset: 0; z-index: 30; display: none; background: rgba(7, 20, 33, .55); }
.backdrop.is-open { display: block; }
.main { min-height: 100vh; padding-bottom: 86px; }
.topbar { height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.94); position: sticky; top: 0; z-index: 20; }
.menu-button { width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--primary); cursor: pointer; }
.topbar-meta { min-width: 0; flex: 1 1 auto; }
.topbar-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .93rem; }
.topbar-meta span { color: var(--muted); font-size: .78rem; }
.user-menu { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.user-menu form { display: none; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: #fff; background: var(--primary); font-weight: 750; }
.content { width: min(1180px, 100%); margin: 0 auto; padding: 24px 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: clamp(1.55rem, 4vw, 2rem); line-height: 1.2; letter-spacing: -.035em; }
.page-head p { margin: 7px 0 0; color: var(--muted); }
.dashboard-logo { width: auto; max-width: 150px; max-height: 64px; object-fit: contain; }
.eyebrow { margin-bottom: 7px; color: var(--secondary); font-size: .8rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }

.grid-metrics { display: grid; grid-template-columns: 1fr; gap: 14px; }
.metric, .panel, .form-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric { min-height: 132px; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-top { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.metric-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--primary); background: #e7eef5; }
.metric-value { margin-top: 18px; font-size: 1.75rem; font-weight: 780; letter-spacing: -.04em; }
.dashboard-grid { display: grid; gap: 18px; margin-top: 18px; }
.panel { padding: 20px; }
.panel h2, .form-card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.panel p, .form-card > p { margin: 0; color: var(--muted); }
.empty-state { min-height: 170px; display: grid; place-items: center; text-align: center; padding: 26px; border: 1px dashed #c3d0db; border-radius: 12px; background: #f9fbfc; margin-top: 18px; }
.empty-state strong { display: block; margin-bottom: 5px; }
.status-line { display: flex; align-items: center; gap: 9px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.status-line:last-child { border-bottom: 0; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); }

.form-card { padding: 20px; }
.settings-stack { display: grid; gap: 18px; }
.settings-section { scroll-margin-top: 88px; }
.settings-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 18px; padding: 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.settings-nav a { min-width: 0; padding: 9px 10px; border-radius: 8px; color: var(--muted); text-align: center; text-decoration: none; font-size: .82rem; font-weight: 700; }
.settings-nav a:hover, .settings-nav a:focus-visible { color: var(--primary); background: var(--surface-muted); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.compact-form { padding: 20px; }
.compact-form h3 { margin: 0 0 14px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 18px; margin-top: 22px; }
.field { display: grid; gap: 7px; }
.field label, .fieldset legend { font-size: .9rem; font-weight: 680; }
.field input, .field select, .field textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #bdcad5; border-radius: 10px; color: var(--text); background: #fff; }
.field textarea { min-height: 100px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18,58,99,.1); outline: 0; }
.field small { color: var(--muted); }
.field input[type="color"] { width: 54px; min-width: 54px; padding: 4px; cursor: pointer; }
.color-field > div { display: flex; gap: 8px; }
.color-field > div input[type="text"], .color-field > div input:not([type]) { flex: 1; }
.field-error { color: var(--danger) !important; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 82px; }
.password-toggle { position: absolute; right: 8px; top: 7px; height: 32px; border: 0; color: var(--primary); background: transparent; font-size: .85rem; font-weight: 700; cursor: pointer; }
.fieldset { grid-column: 1 / -1; padding: 16px; border: 1px solid var(--border); border-radius: 12px; }
.fieldset legend { padding: 0 6px; }
.check-grid { display: grid; gap: 10px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.warning-check { margin-top: 16px; align-items: flex-start; padding: 12px; border-radius: 10px; color: #765014; background: #fff7e7; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); }
.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: 1px solid transparent; border-radius: 10px; background: var(--primary); color: #fff; text-decoration: none; font-weight: 700; cursor: pointer; }
.button:hover { background: var(--primary-strong); }
.button-secondary { color: var(--primary); background: #fff; border-color: var(--border); }
.button-secondary:hover { background: var(--surface-muted); }
.button-danger { color: var(--danger); background: #fff; border-color: #e9c3c3; }
.button-small { min-height: 36px; padding: 7px 11px; font-size: .86rem; }
.link-muted { color: var(--muted); font-weight: 620; }

.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 11px; border: 1px solid; }
.alert-success { color: #0d6848; background: #e9f7f1; border-color: #b9e3d4; }
.alert-error { color: #8d2727; background: #fff0f0; border-color: #efc5c5; }
.alert ul { margin: 0; padding-left: 20px; }

.table-card { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 15px 17px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); background: #f7f9fb; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; }
td { font-size: .92rem; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; align-items: center; gap: 7px; }
.badge { display: inline-flex; align-items: center; min-height: 27px; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 730; }
.badge-success { color: #0e6e4d; background: #e1f5ed; }
.badge-muted { color: #5e6a75; background: #e9eef2; }
.matrix { display: grid; gap: 14px; }
.role-card { padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.role-card h2 { margin: 0; font-size: 1.05rem; }
.role-card p { color: var(--muted); }
.permission-list { display: flex; flex-wrap: wrap; gap: 7px; }

.logo-grid { display: grid; gap: 14px; margin: 22px 0; }
.logo-card { min-width: 0; display: grid; align-content: start; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; }
.logo-card form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.logo-card .field { flex: 1 1 210px; }
.logo-stage { min-height: 130px; display: grid; place-items: center; padding: 18px; border-radius: 10px; color: var(--muted); background: #f2f5f7; }
.logo-stage-dark { color: #d9e4ee; background: #142536; }
.logo-stage img { max-height: 90px; object-fit: contain; }
.color-grid { display: grid; gap: 14px; margin-top: 20px; }
.brand-preview { overflow: hidden; margin-top: 20px; border: 1px solid var(--border); border-radius: 14px; color: var(--preview-text); background: #fff; }
.brand-preview header { min-height: 64px; display: flex; align-items: center; gap: 12px; padding: 12px 18px; color: #fff; background: var(--preview-primary); }
.brand-preview header img { width: auto; max-width: 120px; height: 38px; object-fit: contain; }
.brand-preview > div { padding: 22px; border-top: 5px solid var(--preview-secondary); }
.brand-preview span { color: var(--preview-secondary); font-size: .76rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.brand-preview h3 { margin: 7px 0; }
.brand-preview p { color: #647486; }
.brand-preview button { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 9px; color: #172635; background: var(--preview-accent); font-weight: 750; }
.integration-note { display: grid; gap: 3px; margin-top: 20px; padding: 14px; border: 1px solid #d8e1e8; border-radius: 11px; background: #f7f9fb; }
.integration-note span { color: var(--muted); font-size: .9rem; }
.input-prefix { display: flex; min-width: 0; }
.input-prefix span { display: flex; align-items: center; padding: 0 10px; border: 1px solid #bdcad5; border-right: 0; border-radius: 10px 0 0 10px; color: var(--muted); background: var(--surface-muted); }
.input-prefix input { min-width: 0; border-radius: 0 10px 10px 0; }
.communication-layout { display: grid; gap: 18px; align-items: start; }
.placeholder-guide dl { margin: 18px 0 0; }
.placeholder-guide dl div { padding: 9px 0; border-bottom: 1px solid var(--border); }
.placeholder-guide dt { color: var(--primary); font-family: ui-monospace, monospace; font-weight: 750; }
.placeholder-guide dd { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.message-editor { padding: 20px 0; border-bottom: 1px solid var(--border); }
.message-editor:first-of-type { padding-top: 0; }
.message-editor h2 { margin: 0; }
.message-editor > div > p { margin: 3px 0 14px; color: var(--muted); }
.message-preview { margin-top: 10px; padding: 14px; border-left: 4px solid var(--secondary); border-radius: 8px; background: var(--surface-muted); }
.message-preview strong { font-size: .8rem; }
.message-preview p { margin: 7px 0 0; white-space: pre-wrap; }

.guest-body { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: linear-gradient(145deg, #0c2c4b 0 42%, #f2f6f9 42%); }
.guest-wrap { width: min(940px, 100%); display: grid; border: 1px solid rgba(255,255,255,.2); border-radius: 20px; overflow: hidden; background: var(--surface); box-shadow: 0 24px 70px rgba(5, 20, 34, .2); }
.guest-brand { display: none; padding: 48px; color: #fff; background: var(--primary); }
.guest-brand h1 { margin: 28px 0 12px; font-size: 2.2rem; line-height: 1.1; }
.guest-brand p { color: #c6d5e2; }
.guest-panel { padding: 28px 22px; }
.guest-panel h1 { margin: 22px 0 6px; font-size: 1.7rem; letter-spacing: -.03em; }
.guest-panel > p { margin: 0 0 24px; color: var(--muted); }
.guest-panel .field { margin-bottom: 16px; }
.guest-panel .button { width: 100%; margin-top: 6px; }
.guest-links { display: flex; justify-content: center; margin-top: 20px; font-size: .9rem; }
.guest-footer { margin-top: 26px; color: var(--muted); font-size: .78rem; text-align: center; }
.guest-footer a { color: inherit; }

.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--background); }
.error-card { width: min(560px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 18px; text-align: center; background: var(--surface); box-shadow: var(--shadow); }
.error-code { color: var(--secondary); font-size: .9rem; font-weight: 800; letter-spacing: .12em; }
.error-card h1 { margin: 10px 0; }
.error-card p { color: var(--muted); }
.bottom-nav { position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 25; width: auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 7px; border: 1px solid var(--border); border-radius: 16px; background: rgba(255,255,255,.96); box-shadow: 0 10px 30px rgba(10,30,50,.16); }
.bottom-nav a { min-height: 49px; display: grid; place-items: center; gap: 1px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 680; }
.bottom-nav a.is-active { color: var(--primary); background: #e9f0f6; }
.bottom-nav span:first-child { font-size: 1rem; }

@media (min-width: 620px) {
  .grid-metrics { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-full { grid-column: 1 / -1; }
  .check-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .logo-grid, .color-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guest-panel { padding: 42px; }
}

@media (max-width: 899px) {
  .main, .topbar, .content { width: 100%; min-width: 0; max-width: 100vw; }
  .grid-metrics, .dashboard-grid, .metric, .panel { min-width: 0; }
  .bottom-nav { max-width: calc(100vw - 20px); }
}

@media (min-width: 900px) {
  .sidebar { transform: none; }
  .main { margin-left: 268px; padding-bottom: 0; }
  .menu-button, .bottom-nav { display: none; }
  .user-menu form { display: block; }
  .topbar { padding: 0 30px; }
  .content { padding: 34px 30px 50px; }
  .grid-metrics { grid-template-columns: repeat(4, 1fr); }
  .dashboard-grid { grid-template-columns: 1.5fr 1fr; }
  .guest-wrap { grid-template-columns: 1fr 1fr; }
  .guest-brand { display: block; }
  .settings-nav { grid-template-columns: repeat(6, minmax(0, 1fr)); position: sticky; top: 80px; z-index: 10; }
  .communication-layout { grid-template-columns: minmax(220px, .55fr) minmax(0, 1.45fr); }
  .placeholder-guide { position: sticky; top: 88px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
