:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #e3e6e2;
  --brand: #0f7a5c;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --bubble-in: #ffffff;
  --bubble-ai: #dcf5e8;
  --bubble-agent: #e4ecff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 3px rgba(16, 24, 20, .05);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Tamil", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .85rem; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #0d2b22; color: #cfe3da; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; display: block; }
.sidebar .brand small { display: block; font-weight: 400; color: #8fb3a4; font-size: .78rem; }
.sidebar nav a { display: flex; justify-content: space-between; align-items: center; color: #cfe3da;
  padding: .5rem .6rem; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.sidebar .section { text-transform: uppercase; letter-spacing: .06em; font-size: .7rem; color: #7fa493; margin: 1rem .6rem .35rem; }
.sidebar .foot { position: absolute; bottom: 1rem; left: .75rem; right: .75rem; font-size: .8rem; color: #8fb3a4; }
.sidebar .foot button { background: none; border: 0; color: #cfe3da; cursor: pointer; padding: 0; font: inherit; }
.main { padding: 1.5rem 2rem 3rem; max-width: 1280px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: .9rem 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .15rem; }
.stat.warn .value { color: var(--warn); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbf9; }
.table-wrap { overflow-x: auto; }

/* badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef0ed; color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--brand-soft); color: var(--brand); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: .35rem; }

/* forms */
.input, select.input, textarea.input { width: 100%; padding: .5rem .6rem; border: 1px solid #cfd5d0; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); }
.input:focus { outline: 2px solid rgba(15,122,92,.25); border-color: var(--brand); }
.field { margin-bottom: .85rem; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.field .errorlist { color: var(--danger); list-style: none; padding: 0; margin: .25rem 0 0; font-size: .82rem; }
.field.check-field { display: flex; gap: .5rem; align-items: center; }
.field.check-field label { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f4f6f3; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.filters a { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: .85rem; }
.filters a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.search { max-width: 260px; }

/* flash */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.success { background: var(--brand-soft); border-color: #b9e3d2; color: #0b5e47; }
.flash.error { background: var(--danger-soft); border-color: #f1c4bf; color: var(--danger); }
.flash.info, .flash.warning { background: var(--warn-soft); border-color: #f5d9a8; color: var(--warn); }

/* chat */
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 480px; padding: 0; overflow: hidden; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--line); gap: .75rem; flex-wrap: wrap; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 1rem; background: #eef1ec; }
.bubble-row { display: flex; margin-bottom: .45rem; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.sys { justify-content: center; }
.bubble { max-width: 72%; padding: .5rem .7rem; border-radius: 10px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.bubble.ai { background: var(--bubble-ai); }
.bubble.agent { background: var(--bubble-agent); }
.bubble.system { background: transparent; box-shadow: none; color: var(--muted); font-size: .8rem; padding: .2rem; }
.bubble .meta { display: block; font-size: .7rem; color: var(--muted); margin-top: .25rem; text-align: right; white-space: normal; }
.bubble .meta .route { text-transform: uppercase; letter-spacing: .03em; }
.bubble.failed { outline: 1px solid var(--danger); }
.composer { border-top: 1px solid var(--line); padding: .75rem; background: #fff; }
.composer form { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { resize: vertical; min-height: 44px; }
.banner { padding: .55rem 1rem; font-size: .88rem; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.human { background: var(--info-soft); color: var(--info); }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: .4rem 0; display: flex; gap: .5rem; align-items: center; border-bottom: 1px dashed var(--line); }
.checklist li:last-child { border-bottom: 0; }
.tick { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; flex: none; }
.tick.done { background: var(--brand); color: #fff; }
.tick.todo { border: 2px solid #c8cfca; }

.bar { height: 8px; background: #eef0ed; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: .25rem .75rem; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.pagination { display: flex; gap: .5rem; align-items: center; margin-top: .75rem; }
code.copy { background: #f1f3f0; padding: .15rem .4rem; border-radius: 6px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .sidebar .section, .sidebar .foot { display: none; }
  .main { padding: 1rem 16px 2rem; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid, .chat-layout { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
}
