/* K.R.N Weight Program — shared styles */
:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1f2933; --muted: #64707d; --line: #e3e7eb;
  --pri: #0f766e; --pri-d: #0b5c56; --pri-l: #e6f4f2;
  --red: #c2410c; --red-l: #fdecea; --amber: #b45309; --amber-l: #fef5e4;
  --green: #15803d; --green-l: #e8f6ec; --blue: #1d4ed8; --blue-l: #e8effd;
  --purple: #7c3aed; --purple-l: #f1ebfd; --orange: #c2410c; --orange-l: #fdf0e6;
  --gray-l: #eef0f2; --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans Tamil", "Latha", Roboto, sans-serif;
  color: var(--ink); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
a { color: var(--pri); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: .4em; justify-content: center; padding: .5em .95em; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f7f8f9; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.danger { color: var(--red); }
.btn.sm { padding: .3em .65em; font-size: .85rem; }
.btn.big { padding: .75em 1.3em; font-size: 1.02rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 .2em; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .15em .6em; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--gray-l); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-l); color: var(--green); } .badge.amber { background: var(--amber-l); color: var(--amber); }
.badge.red { background: var(--red-l); color: var(--red); } .badge.blue { background: var(--blue-l); color: var(--blue); }
.badge.purple { background: var(--purple-l); color: var(--purple); } .badge.teal { background: var(--pri-l); color: var(--pri); }
.badge.orange { background: var(--orange-l); color: var(--orange); } .badge.gray { background: var(--gray-l); color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: #fff; border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; }
.brand .logo { width: 38px; height: 38px; border-radius: 10px; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: 8px; color: var(--ink); text-decoration: none; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a.on { background: var(--pri-l); color: var(--pri); }
.nav .ico { width: 1.3em; text-align: center; }
.side-foot { margin-top: auto; padding: .5rem; font-size: .85rem; color: var(--muted); }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .who { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.demo-bar { background: #fff7e0; color: #7a5a00; text-align: center; padding: .35rem; font-size: .85rem; border-bottom: 1px solid #f1e2b0; }
#view { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.bottomnav { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* ---------- cards & grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card > h3:first-child { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); display: block; }
a.stat:hover { border-color: var(--pri); }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--red); } .stat.warn .n { color: var(--amber); } .stat.good .n { color: var(--green); }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 160px; }
.list a.row-link { color: var(--ink); text-decoration: none; font-weight: 600; }
.list a.row-link:hover { color: var(--pri); }
.empty { color: var(--muted); padding: 1.2rem 0; text-align: center; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { padding: .35em .85em; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: .88rem; text-decoration: none; color: var(--ink); }
.chip.on { background: var(--pri); border-color: var(--pri); color: #fff; }
.chip .c { opacity: .7; margin-left: .25em; }
.search { width: 100%; max-width: 360px; padding: .55em .85em; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #f9fafb; }
.up { color: var(--red); } .down { color: var(--green); }

/* ---------- client profile ---------- */
.profile-head { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.avatar { width: 54px; height: 54px; border-radius: 50%; background: var(--pri-l); color: var(--pri); display: grid; place-items: center; font-weight: 700; font-size: 1.3rem; flex: none; }
.ph-left { display: flex; gap: .9rem; align-items: center; }
.ph-left h1 { margin: 0; font-size: 1.35rem; }
.meta { color: var(--muted); font-size: .9rem; display: flex; gap: .4rem .9rem; flex-wrap: wrap; margin-top: .15rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 1rem 0 1.1rem; overflow-x: auto; }
.tabs a { padding: .6rem .95rem; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--pri); border-bottom-color: var(--pri); }
.flags { border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.flags.high { background: var(--red-l); border-color: #f5c6bd; }
.flags.caution { background: var(--amber-l); border-color: #f3dfb5; }
.flags b { display: block; margin-bottom: .3rem; }
.flags ul { margin: 0; padding-left: 1.2rem; }
.flags li.h { color: var(--red); font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: .45rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.pre { white-space: pre-wrap; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #edf0f2; } .chart .axis { fill: #7b8794; font-size: 12px; }
.chart .goal { stroke: var(--green); stroke-dasharray: 5 4; } .chart .goal-label { fill: var(--green); font-size: 12px; font-weight: 600; }
.chart-empty { color: var(--muted); text-align: center; padding: 2rem 0; font-size: .9rem; }
.plan-box { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; white-space: pre-wrap; }
.targets { display: flex; gap: .5rem; flex-wrap: wrap; margin: .4rem 0 .8rem; }
.targets span { background: var(--pri-l); color: var(--pri); border-radius: 8px; padding: .3em .7em; font-size: .88rem; font-weight: 600; }
details.history summary { cursor: pointer; color: var(--pri); font-weight: 500; margin: .5rem 0; }
.entry { border-top: 1px solid var(--line); padding: .8rem 0; }
.entry:first-child { border-top: 0; padding-top: 0; }
.entry-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin-bottom: .4rem; flex-wrap: wrap; }

/* ---------- forms / modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem .4rem; }
.modal-head h3 { margin: 0; }
.modal-body { padding: .6rem 1.2rem 1rem; display: flex; flex-wrap: wrap; gap: .8rem; }
.modal-foot { padding: .9rem 1.2rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; }
.fld { display: flex; flex-direction: column; gap: .3rem; width: 100%; font-size: .9rem; }
.fld.half { width: calc(50% - .4rem); } .fld.third { width: calc(33.33% - .55rem); }
.fld > span { color: var(--muted); font-weight: 500; }
.fld input, .fld select, .fld textarea, .q input, .q textarea { padding: .55em .7em; border: 1px solid #cfd6dd; border-radius: 8px; background: #fff; width: 100%; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .q input:focus, .q textarea:focus, .search:focus { outline: 2px solid var(--pri-l); border-color: var(--pri); }
.fld .hint { color: var(--muted); font-size: .8rem; }
.section-label { width: 100%; font-weight: 700; color: var(--pri); margin-top: .4rem; font-size: .9rem; }
.copybox { width: 100%; background: #f6f8fa; border: 1px solid var(--line); border-radius: 8px; padding: .7rem; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: 100%; max-width: 400px; padding: 1.8rem; }
.login .brand { padding: 0 0 1.2rem; }
.login form { display: flex; flex-direction: column; gap: .9rem; }
.login .err { color: var(--red); font-size: .9rem; min-height: 1.2em; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast { background: #1f2933; color: #fff; padding: .65rem 1.1rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: opacity .4s; font-size: .92rem; }
.toast.error { background: var(--red); } .toast.out { opacity: 0; }
.loading { color: var(--muted); padding: 2rem; text-align: center; }

/* ---------- registration form (client facing) ---------- */
.reg-body { min-height: 100vh; background: var(--bg) linear-gradient(180deg, #e6f4f2 0, var(--bg) 260px) no-repeat; }
.reg-wrap { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.reg-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.reg-head .brand { padding: .25rem 0; }
.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.lang-switch button { border: 0; background: none; padding: .45em 1em; cursor: pointer; }
.lang-switch button.on { background: var(--pri); color: #fff; }
.reg-progress { height: 6px; background: #dbe5e3; border-radius: 99px; margin: .8rem 0 1rem; overflow: hidden; }
.reg-progress > div { height: 100%; background: var(--pri); width: 0; transition: width .3s; }
.reg-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 1.4rem 1.3rem; }
.reg-step { color: var(--muted); font-size: .85rem; margin-bottom: .2rem; }
.reg-hello { font-size: 1.15rem; font-weight: 600; }
.reg-intro { color: var(--muted); }
.q { margin: 1.1rem 0; }
.q-label { font-weight: 600; margin-bottom: .45rem; }
.q .opt { color: var(--muted); font-weight: 400; font-size: .85rem; }
.q .hint { color: var(--muted); font-size: .82rem; margin: -.2rem 0 .4rem; }
.q input, .q textarea { font-size: 1rem; padding: .7em .8em; }
.q.bad input, .q.bad textarea, .q.bad .choices { border-color: var(--red); }
.q-err { color: var(--red); font-size: .85rem; margin-top: .3rem; }
.q-err:empty { display: none; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; border-radius: 10px; }
.choice { display: flex; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { padding: .6em 1em; border: 1.5px solid #cfd6dd; border-radius: 10px; cursor: pointer; background: #fff; user-select: none; }
.choice input:checked + span { border-color: var(--pri); background: var(--pri-l); color: var(--pri-d); font-weight: 600; }
.choice input:focus-visible + span { outline: 2px solid var(--pri); }
.consent { display: flex; gap: .7rem; align-items: flex-start; padding: .85rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .6rem; cursor: pointer; }
.consent input { width: 22px; height: 22px; flex: none; margin-top: .1rem; accent-color: var(--pri); }
.reg-nav { display: flex; justify-content: space-between; gap: .8rem; margin-top: 1.4rem; }
.reg-msg { text-align: center; padding: 1.5rem .5rem; }
.reg-msg-icon { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 1rem; display: grid; place-items: center; font-size: 2rem; font-weight: 700; background: var(--green-l); color: var(--green); }
.reg-msg.bad .reg-msg-icon { background: var(--red-l); color: var(--red); }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar { padding: .7rem 1rem; }
  #view { padding: 1rem 1rem 5.5rem; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; text-align: center; padding: .5rem 0 .55rem; color: var(--muted); text-decoration: none; font-size: .72rem; }
  .bottomnav a .ico { display: block; font-size: 1.25rem; }
  .bottomnav a.on { color: var(--pri); }
  .g2, .g3, .charts { grid-template-columns: 1fr; }
  .fld.half, .fld.third { width: 100%; }
  .hide-m { display: none; }
  .modal-wrap { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; max-width: none; min-height: 100%; }
  .kv { grid-template-columns: 1fr; gap: .1rem; } .kv dd { margin-bottom: .5rem; }
}
@media print {
  .sidebar, .topbar, .bottomnav, .demo-bar, .tabs, .btn, .row-actions { display: none !important; }
  #view { padding: 0; } .card { box-shadow: none; break-inside: avoid; }
}
