/* Towly Console v3 - warm admin theme. No horizontal overflow by design. */
:root {
  --bg: #161310;
  --bg-soft: #1e1a15;
  --bg-raised: #262019;
  --bg-hover: #2e2620;
  --border: #3a322a;
  --border-soft: #2c2620;
  --text: #ece6d9;
  --text-dim: #b8ad99;
  --text-faint: #8a7f6c;
  --accent: #d9a648;
  --accent-soft: rgba(217, 166, 72, 0.14);
  --accent-text: #f0c778;
  --green: #7fb069;
  --green-soft: rgba(127, 176, 105, 0.14);
  --red: #d9685c;
  --red-soft: rgba(217, 104, 92, 0.13);
  --blue: #7aa5d2;
  --blue-soft: rgba(122, 165, 210, 0.14);
  --amber: #d9a648;
  --amber-soft: rgba(217, 166, 72, 0.14);
  --sidebar: #100d0a;
  --sidebar-active: #262019;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="light"] {
  --bg: #faf7f0;
  --bg-soft: #f3eee3;
  --bg-raised: #ffffff;
  --bg-hover: #ece5d5;
  --border: #ddd2bd;
  --border-soft: #e9e1d0;
  --text: #2b2419;
  --text-dim: #6b5f4c;
  --text-faint: #9a8d76;
  --accent: #b07f1f;
  --accent-soft: rgba(176, 127, 31, 0.12);
  --accent-text: #8a5f10;
  --green: #4a7c3a;
  --green-soft: rgba(74, 124, 58, 0.12);
  --red: #b04336;
  --red-soft: rgba(176, 67, 54, 0.1);
  --blue: #2f6db3;
  --blue-soft: rgba(47, 109, 179, 0.1);
  --amber: #b07f1f;
  --amber-soft: rgba(176, 127, 31, 0.12);
  --sidebar: #241d14;
  --sidebar-active: #3a2f22;
  --shadow: 0 8px 28px rgba(60, 45, 20, 0.12);
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== shell layout ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px;
  background: var(--sidebar);
  color: #ece6d9;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto; overflow-x: hidden;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px; color: #ece6d9; font-weight: 700; font-size: 17px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 30px;
  background: var(--accent); color: #1a140d;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
}
.nav-section { padding: 10px 12px 4px; }
.nav-label {
  font-size: 10.5px; letter-spacing: 0.09em; text-transform: uppercase;
  color: #8a7f6c; padding: 8px 10px 4px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: 8px;
  color: #cfc4ae; font-size: 13.5px; font-weight: 500;
  margin: 1px 0;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; flex: 0 0 18px; opacity: 0.85; }
.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--accent); color: #1a140d;
  border-radius: 20px; padding: 1px 8px;
}
.sidebar-foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.tenant-pill {
  display: flex; align-items: center; gap: 9px;
  background: rgba(255,255,255,0.06); border-radius: 8px; padding: 8px 10px;
  color: #ece6d9; font-size: 13px; cursor: pointer; border: 0; width: 100%; text-align: left;
}
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  position: sticky; top: 0; z-index: 30;
}
.topbar .crumb { color: var(--text-faint); font-size: 13px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-raised); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.user-chip {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-raised);
  border-radius: 20px; padding: 4px 12px 4px 4px; color: var(--text);
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 26px;
  background: var(--accent-soft); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.avatar.lg { width: 40px; height: 40px; font-size: 15px; flex-basis: 40px; }
.content { padding: 26px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ===== page head ===== */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { color: var(--text-dim); margin: 4px 0 0; font-size: 13.5px; max-width: 640px; }
.page-head .actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--text);
  border-radius: 8px; padding: 8px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a140d; }
.btn.primary:hover { filter: brightness(1.07); color: #1a140d; }
.btn.danger { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== cards / panels ===== */
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--bg-raised); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 18px;
}
.card h3 { margin: 0 0 6px; font-size: 14px; }
.stat-num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.stat-delta { font-size: 12px; margin-top: 6px; }
.up { color: var(--green); } .down { color: var(--red); }
.panel { background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

/* ===== tables ===== */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); font-weight: 700; padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft); white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl .rowlink { cursor: pointer; }
.empty { padding: 38px 20px; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 30px; margin-bottom: 8px; }

/* ===== badges / pills ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; border-radius: 20px; padding: 2px 10px;
  white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: var(--bg-hover); color: var(--text-dim); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ===== tabs ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-soft); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; color: var(--text-dim); font-weight: 600; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* ===== forms ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text-dim); }
.input, .select, textarea.input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 9px 12px; font-size: 13.5px;
  font-family: inherit;
}
.input:focus, .select:focus, textarea.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea.input { min-height: 90px; resize: vertical; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.search { position: relative; }
.search .input { padding-left: 34px; }
.search .s-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .search { flex: 1 1 220px; max-width: 340px; }

/* ===== modal / drawer ===== */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px; overflow-y: auto;
}
.modal {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border-soft); }

/* ===== toasts ===== */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: min(360px, 90vw); }
.toast {
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 15px; box-shadow: var(--shadow); font-size: 13.5px;
  display: flex; gap: 10px; align-items: flex-start;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }

/* ===== detail layout ===== */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-faint); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 24px; font-size: 13px; }
.timeline li::before {
  content: ""; position: absolute; left: 6px; top: 6px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.timeline li::after {
  content: ""; position: absolute; left: 9px; top: 18px; bottom: -2px; width: 2px;
  background: var(--border);
}
.timeline li:last-child::after { display: none; }
.timeline .t { color: var(--text-faint); font-size: 12px; }
code.mono, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
pre.code {
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; font-size: 12.5px; margin: 0;
}
.progress { height: 8px; border-radius: 6px; background: var(--bg-hover); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.conf-bar { display: flex; align-items: center; gap: 10px; }
.conf-bar .progress { flex: 1; }

/* ===== responsive ===== */
.menu-toggle { display: none; }
@media (max-width: 1020px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: minmax(0, 1fr); }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .page-head .actions { margin-left: 0; }
  .topbar { padding: 10px 14px; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { margin-top: 8px; }
}
.scrim { display: none; }
@media (max-width: 760px) {
  .scrim.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35; }
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
