@font-face {
  font-family: "DM Sans";
  src: url("fonts/dm-sans.woff2") format("woff2");
  font-weight: 100 1000;
  font-display: swap;
}
:root {
  --brand: #166655;
  --brand-hover: #104e40;
  --brand-soft: #e8f4f1;
  --brand-border: #bce0d7;
  --ink: #12201e;
  --ink-secondary: #4c615d;
  --muted: #52695f;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-alt: #f8fbfa;
  --border: #dce6e3;
  --danger: #c63737;
  --danger-soft: #fdeeee;
  --warn: #b86e00;
  --warn-soft: #fff6e5;
  --ok: #137547;
  --ok-soft: #e7f6ee;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(16, 36, 32, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Workspace navigation */
.app-shell {
  display: grid;
  grid-template: "sidebar header" auto "sidebar main" 1fr / 232px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 23px;
  padding: 23px 14px 16px;
  background: #14352c;
  color: #f2faf4;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  align-self: flex-start;
  padding-inline: 9px;
  color: inherit;
  text-decoration: none !important;
}
.brand-logo strong {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.045em;
  line-height: 1;
}
.nav-list { display: grid; gap: 3px; }
.nav-section-title {
  padding: 0 12px 6px;
  color: #a7c5b6;
  font-size: 12px;
  font-weight: 530;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #dae8de;
  font-size: 14px;
  font-weight: 520;
  text-decoration: none !important;
}
.panel-icon {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item:hover { color: white; background: #244b3f; }
.nav-item.active { background: #d9ecdc; color: #153f2f; font-weight: 650; }
.sidebar-bottom {
  display: grid;
  gap: 6px;
  margin-top: auto;
  padding: 15px 10px 0;
  border-top: 1px solid #3b594d;
  font-size: 13px;
  color: #b5d0c1;
}
.sidebar-bottom a { display: inline-flex; align-items: center; gap: 8px; color: #edf6ee; }
.sidebar-bottom .panel-icon { width: 14px; height: 14px; transform: rotate(-40deg); }
.topbar {
  grid-area: header;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 9px clamp(20px, 3vw, 46px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-left, .panel-workspace, .panel-account summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.panel-workspace > span, .panel-workspace label { color: var(--ink-secondary); font-size: 13px; }
.panel-workspace > strong, .panel-workspace select {
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 650;
}
.panel-workspace select { width: auto; min-width: 0; padding: 6px 9px; }
.panel-menu-toggle { display: none; }
.panel-account { position: relative; }
.panel-account summary {
  border-radius: 7px;
  cursor: pointer;
  list-style: none;
  font-size: 14px;
  font-weight: 550;
}
.panel-account summary::-webkit-details-marker { display: none; }
.panel-account summary .panel-icon { width: 14px; height: 14px; }
.account-name { max-width: 22ch; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.avatar-circle {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #dfede2;
  color: var(--brand);
  font-weight: 680;
}
.account-popover {
  position: absolute;
  right: 0;
  z-index: 4;
  display: grid;
  gap: 2px;
  min-width: 171px;
  margin-top: 8px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  box-shadow: 0 8px 22px rgb(24 57 38 / 10%);
}
.account-popover a, .account-popover button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.account-popover a:hover, .account-popover button:hover { background: var(--brand-soft); text-decoration: none; }
.content-container {
  grid-area: main;
  width: 100%;
  max-width: 1232px;
  min-width: 0;
  margin: 0 auto;
  padding: 32px clamp(20px, 3vw, 46px) 50px;
}
.panel-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.panel-skip { position: fixed; top: 7px; left: 12px; z-index: 10; transform: translateY(-160%); background: #fff; padding: 8px 14px; border-radius: 6px; }
.panel-skip:focus { transform: none; }
:focus-visible { outline: 2px solid #178467; outline-offset: 3px; }
.sidebar :focus-visible { outline-color: #b2e5b9; }

/* Signed-out forms */
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px 16px;
  background: #f4f7f2;
}
.auth-shell > .brand-logo { align-self: center; margin-bottom: 22px; color: var(--ink); }
.auth-shell > .alert { width: min(100%, 460px); }
.auth-card .form-turnstile { min-width: 0; margin: 0 0 16px; }
.registration-form .form-turnstile { margin: 0; }
.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 12px 32px rgba(15, 36, 32, 0.07);
}

/* Headings, Cards, Grid */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 25px;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 14.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
}

.card-subtitle {
  margin: 0 0 16px;
  color: var(--ink-secondary);
  font-size: 13.5px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

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

/* Badges & Alerts */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-neutral {
  background: #edf2f0;
  color: var(--ink-secondary);
}

.alert {
  padding: 13px 16px;
  border-radius: 11px;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 500;
}

.alert-ok {
  background: var(--ok-soft);
  border: 1px solid #b7e4c7;
  color: #0e5a36;
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid #f5c2c2;
  color: #9e2222;
}

.alert-info {
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  color: var(--brand-hover);
}

/* Forms & Buttons */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}

.field small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cad7d3;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #ffffff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22, 102, 85, 0.14);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--brand);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9.5px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none !important;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--brand);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-secondary {
  background: #ffffff;
  border-color: #c8d6d2;
  color: var(--ink);
}

.btn-secondary:hover {
  background: var(--surface-alt);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #f2c1c1;
  color: var(--danger);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid #edf2f0;
  vertical-align: top;
}

/* Rule Flow & WhatsApp Preview */
.rule-card {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 18px 20px;
  background: var(--surface);
  margin-bottom: 14px;
}

.rule-flow-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0;
  font-size: 13px;
}

.flow-pill {
  padding: 5px 11px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-weight: 500;
}

.wa-bubble {
  background: #e7ffdb;
  border: 1px solid #c5e8b7;
  border-radius: 12px 12px 12px 3px;
  padding: 12px 15px;
  font-size: 13.5px;
  white-space: pre-wrap;
  color: #111b15;
  max-width: 580px;
}

.qr-frame {
  display: inline-flex;
  padding: 16px;
  background: #ffffff;
  border: 2px dashed var(--brand-border);
  border-radius: 16px;
}

.template-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

@media (max-width: 960px) {
  .app-shell { grid-template: "header" auto "sidebar" auto "main" 1fr / minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 15px 18px; gap: 17px; }
  .sidebar > .brand-logo { display: none; }
  .app-shell[data-nav-ready] .sidebar { display: none; }
  .app-shell[data-nav-ready].nav-open .sidebar { display: flex; }
  .app-shell[data-nav-ready] .panel-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: white;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
  }
  .topbar { min-height: 58px; padding: 8px 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .content-container { padding: 24px 18px 36px; }
}
@media (max-width: 620px) {
  .topbar { gap: 8px; }
  .panel-workspace > span, .panel-workspace > label, .account-name { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
  .panel-workspace select { max-width: 40vw; }
  .panel-account summary { gap: 3px; }
  .card { padding: 18px; }
}
