:root {
  --ih-bg: #f4f6fb;
  --ih-sidebar: #131a2b;
  --ih-sidebar-2: #1c2438;
  --ih-accent: #2ea56b;
  --ih-accent-2: #2563eb;
  --ih-text: #1f2a44;
  --ih-muted: #6b7690;
  --ih-border: #e5e9f2;
  --ih-card: #ffffff;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--ih-bg);
  color: var(--ih-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- App shell ---------- */
.ih-app { display: flex; min-height: 100vh; }

.ih-sidebar {
  width: 244px;
  background: linear-gradient(180deg, var(--ih-sidebar), var(--ih-sidebar-2));
  color: #cdd5e6;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.ih-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.ih-logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--ih-accent); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.ih-brand strong { color: #fff; display: block; font-size: 15px; }
.ih-brand small { color: #8b95ad; font-size: 11px; }

.ih-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.ih-nav .nav-section { color: #6c7690; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 12px 4px; }
.ih-link {
  color: #c2cad9; text-decoration: none; padding: 9px 12px; border-radius: 8px;
  font-size: 13.5px; display: flex; align-items: center; gap: 9px; transition: all .12s;
}
.ih-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.ih-link.active { background: var(--ih-accent); color: #fff; font-weight: 600; }

.ih-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ih-topbar {
  height: 60px; background: #fff; border-bottom: 1px solid var(--ih-border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.ih-title { font-size: 17px; font-weight: 650; }
.ih-user { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--ih-muted); }
.ih-user a { color: var(--ih-accent-2); text-decoration: none; }
.ih-user .badge-user { background: #eef1f8; color: #33405e; padding: 5px 11px; border-radius: 20px; font-weight: 600; }
.ih-user form { margin: 0; }
.ih-user button {
  background: #fff; border: 1px solid var(--ih-border); color: #d1495b;
  padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
}
.ih-user button:hover { background: #fff5f6; }

.ih-content { padding: 24px; max-width: 1240px; width: 100%; }

/* ---------- Cards ---------- */
.ih-card {
  background: var(--ih-card); border: 1px solid var(--ih-border);
  border-radius: 12px; padding: 18px 20px; box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
.ih-card + .ih-card { margin-top: 18px; }
.ih-card h2, .ih-card h3 { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-sub { color: var(--ih-muted); font-size: 12.5px; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  background: #fff; border: 1px solid var(--ih-border); border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
.stat .label { color: var(--ih-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--ih-muted); margin-top: 2px; }
.stat.accent { border-left: 3px solid var(--ih-accent); }
.stat.blue { border-left: 3px solid var(--ih-accent-2); }
.stat.warn { border-left: 3px solid #e0a800; }
.stat.danger { border-left: 3px solid #d1495b; }

/* ---------- Tables ---------- */
.ih-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ih-table th {
  text-align: left; color: var(--ih-muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--ih-border);
}
.ih-table td { padding: 10px 12px; border-bottom: 1px solid #f0f2f8; vertical-align: top; }

/* Sortable column headings. The arrow is always in the markup so a heading does not
   shift sideways when it becomes the sorted one; it is only faint until then. */
.ih-table th a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
.ih-table th a.sort:hover { color: var(--ih-accent-2); }
.ih-table th a.sort .arr { font-size: 9px; margin-left: 4px; opacity: .3; }
.ih-table th a.sort.on { color: #33405e; }
.ih-table th a.sort.on .arr { opacity: 1; color: var(--ih-accent-2); }
.ih-table th.chk, .ih-table td.chk { width: 28px; padding-right: 0; }
.ih-table td.chk input, .ih-table th.chk input { margin: 0; cursor: pointer; }
.ih-table tr:hover td { background: #fafbfe; }
.ih-table code { font-size: 12px; }
.table-scroll { overflow-x: auto; }

/* ---------- Badges ---------- */
.badge2 { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.b-green { background: #e3f6ec; color: #1c7a48; }
.b-blue { background: #e5edff; color: #1d4ed8; }
.b-gray { background: #eef1f6; color: #55607a; }
.b-amber { background: #fdf1d8; color: #9a6b00; }
.b-red { background: #fbe4e8; color: #b1263c; }
.b-purple { background: #efe6fb; color: #6b34c0; }

/* status dot */
.dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.dot.on { background: var(--ih-accent); }
.dot.off { background: #c3cad8; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.fld label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #3a465f; }
.fld input, .fld select, .fld textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--ih-border); border-radius: 8px;
  font-size: 13.5px; background: #fff; font-family: inherit;
}
.fld textarea { resize: vertical; min-height: 90px; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--ih-accent-2); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.hint { color: var(--ih-muted); font-size: 11.5px; margin-top: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- Buttons ---------- */
.btn2 { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn2.primary { background: var(--ih-accent); color: #fff; }
.btn2.primary:hover { background: #268a5a; }
.btn2.blue { background: var(--ih-accent-2); color: #fff; }
.btn2.ghost { background: #fff; border-color: var(--ih-border); color: #33405e; }
.btn2.ghost:hover { background: #f6f8fc; }
.btn2.danger { background: #fff; border-color: #f2c2cb; color: #c1273f; }
.btn2.danger:hover { background: #fdeef1; }
.btn2.sm { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Misc ---------- */
.flash { padding: 11px 15px; border-radius: 9px; margin-bottom: 16px; font-size: 13.5px; }
.flash.ok { background: #e3f6ec; color: #1c7a48; border: 1px solid #bfe6cf; }
.flash.err { background: #fbe4e8; color: #b1263c; border: 1px solid #f2c2cb; }
.flash.info { background: #e5edff; color: #1d4ed8; border: 1px solid #c9d8fb; }
pre.code {
  background: #0f1524; color: #d6e0f5; border-radius: 10px; padding: 16px; overflow: auto;
  font-size: 12.5px; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; font-size: 13px; }
.kv .k { color: var(--ih-muted); }
.copy-field { display: flex; gap: 8px; align-items: center; }
.copy-field input { flex: 1; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; font-size: 13px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters .fld { min-width: 150px; }
.muted { color: var(--ih-muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
a.plain { color: var(--ih-accent-2); text-decoration: none; }
a.plain:hover { text-decoration: underline; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#131a2b,#243354); padding: 20px; }
.auth-card { background: #fff; border-radius: 16px; padding: 34px 32px; width: 100%; max-width: 390px; box-shadow: 0 24px 60px rgba(10,18,40,.35); }
.auth-brand { display:flex; align-items:center; gap:12px; margin-bottom: 6px; }
.auth-brand .ih-logo { width: 42px; height: 42px; font-size: 16px; }
.auth-card h1 { font-size: 20px; margin: 14px 0 2px; }
.auth-card p.sub { color: var(--ih-muted); font-size: 13px; margin: 0 0 20px; }

/* ---------- Template library: editor + WhatsApp preview ---------- */
.tpl-split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.tpl-preview-card { position: sticky; top: 16px; }
.tpl-buttons td { vertical-align: middle; }
.tpl-buttons input, .tpl-buttons select { width: 100%; }
.tpl-buttons input + input { margin-top: 6px; }

.wa-wrap {
  background: #e5ddd5;
  background-image: radial-gradient(rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: 14px 14px;
  border-radius: 12px; padding: 16px 14px 18px;
}
.wa-bubble {
  background: #fff; border-radius: 8px 8px 8px 2px; padding: 8px 10px 6px;
  box-shadow: 0 1px 1px rgba(11,20,26,.18); font-size: 13.5px; line-height: 1.45;
  color: #111b21; word-break: break-word; position: relative;
}
.wa-header { font-weight: 700; margin-bottom: 4px; }
.wa-header-media {
  background: #f0f2f5; border: 1px dashed #c8d0d6; border-radius: 6px;
  padding: 18px 10px; text-align: center; font-weight: 600; color: #667781; margin-bottom: 6px;
}
.wa-media { display: block; font-size: 11px; letter-spacing: .08em; }
.wa-media-url { display: block; font-size: 10.5px; font-weight: 400; margin-top: 5px; word-break: break-all; color: #8696a0; }
.wa-body { white-space: normal; }
.wa-footer { color: #8696a0; font-size: 11.5px; margin-top: 6px; }
.wa-time { color: #8696a0; font-size: 10.5px; text-align: right; margin-top: 2px; }
.wa-var { background: #fff3cd; color: #7a5b00; border-radius: 3px; padding: 0 3px; font-weight: 600; }
.wa-buttons { margin-top: 3px; display: flex; flex-direction: column; gap: 3px; }
.wa-btn {
  background: #fff; color: #0a80ff; border-radius: 6px; padding: 8px; text-align: center;
  font-size: 13px; font-weight: 500; box-shadow: 0 1px 1px rgba(11,20,26,.18); word-break: break-all;
}

@media (max-width: 1100px) {
  .tpl-split { grid-template-columns: 1fr; }
  .tpl-preview-card { position: static; }
}

@media (max-width: 820px) {
  .ih-sidebar { width: 64px; }
  .ih-brand div, .ih-brand small, .ih-nav .nav-section { display: none; }
  .ih-link { justify-content: center; }
  .ih-link span.txt { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
