/* CalorieAI Admin — Apple-inspired, light & dark */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --glass: rgba(255, 255, 255, .72);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, .08);
  --accent: #1f9d55;
  --accent-soft: rgba(31, 157, 85, .12);
  --blue: #0071e3;
  --red: #d70015;
  --amber: #b25000;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans Myanmar", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #232325;
    --glass: rgba(28, 28, 30, .72);
    --text: #f5f5f7;
    --muted: #98989d;
    --line: rgba(255, 255, 255, .1);
    --accent: #30d158;
    --accent-soft: rgba(48, 209, 88, .15);
    --blue: #0a84ff;
    --red: #ff453a;
    --amber: #ff9f0a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { letter-spacing: -.01em; margin: 0; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
small { color: var(--muted); }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #34c759, #1f9d55); }
.brand strong { display: block; font-size: 15px; }
.brand small { font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 9px; color: var(--text); font-weight: 500; }
.sidebar nav a svg { color: var(--muted); }
.sidebar nav a:hover { background: var(--line); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar nav a.active svg { color: var(--accent); }
.sidebar nav .count { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; background: var(--red); color: #fff; border-radius: 10px; padding: 1px 7px; }
.sidebar-foot { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.sidebar-foot .me { display: flex; gap: 10px; align-items: center; flex: 1; color: var(--text); padding: 6px; border-radius: 9px; min-width: 0; }
.sidebar-foot .me:hover { background: var(--line); text-decoration: none; }
.sidebar-foot .me small, .sidebar-foot .me strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.logout { color: var(--muted); padding: 8px; border-radius: 8px; }
.logout:hover { background: var(--line); color: var(--red); }
.main { flex: 1; min-width: 0; padding: 22px 32px 48px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.topbar h1 { font-size: 26px; font-weight: 700; }
.menu-btn { display: none; border: 0; background: var(--surface); border-radius: 8px; padding: 6px 10px; font-size: 18px; color: var(--text); }

/* Cards & grid */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .sub .up { color: var(--accent); font-weight: 600; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* Badges & alerts */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--accent-soft); color: var(--accent); }
.badge-red { background: rgba(215, 0, 21, .1); color: var(--red); }
.badge-amber { background: rgba(255, 149, 0, .14); color: var(--amber); }
.badge-blue { background: rgba(0, 113, 227, .1); color: var(--blue); }
.badge-grey { background: var(--line); color: var(--muted); }
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.alert-success { background: var(--accent-soft); color: var(--accent); }
.alert-error { background: rgba(215, 0, 21, .1); color: var(--red); }
.alert-info { background: rgba(0, 113, 227, .1); color: var(--blue); }

/* Forms */
form.inline { display: inline; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field small { display: block; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, .2); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13px; padding: 8px 15px; border-radius: 980px; border: 1px solid transparent; cursor: pointer; background: var(--accent); color: #fff; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn-secondary { background: var(--line); color: var(--text); }
.btn-danger { background: rgba(215, 0, 21, .1); color: var(--red); }
.btn-blue { background: var(--blue); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.repeater-row { display: grid; grid-template-columns: 1fr 140px 90px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }

/* Detail list */
dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; }

/* Bar chart */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar span { width: 100%; background: linear-gradient(180deg, #34c759, #1f9d55); border-radius: 6px 6px 3px 3px; min-height: 2px; }
.bars .bar small { font-size: 10px; }
.bars .bar b { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Pagination */
.pagination { display: flex; gap: 6px; align-items: center; padding: 14px 20px; flex-wrap: wrap; }
.pagination a, .pagination span.current { padding: 4px 11px; border-radius: 8px; background: var(--line); color: var(--text); font-weight: 500; }
.pagination span.current { background: var(--accent); color: #fff; }
.pagination .muted { margin-left: auto; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(52, 199, 89, .25), transparent 40%), radial-gradient(circle at 80% 80%, rgba(0, 113, 227, .2), transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--glass); backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px); border: 1px solid var(--line); border-radius: 22px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.08); }
.login-card .brand { justify-content: center; flex-direction: column; text-align: center; padding-bottom: 22px; }
.login-card .brand-mark { width: 52px; height: 52px; border-radius: 15px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: block; }
  .main { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; }
  .repeater-row { grid-template-columns: 1fr 1fr; }
}

/* Phase 3 */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: rgba(118,118,128,.12); padding: 3px; border-radius: 10px; width: fit-content; margin-bottom: 16px; }
.tabs a { padding: 6px 14px; border-radius: 8px; color: var(--text); font-weight: 500; font-size: 13px; text-decoration: none; }
.tabs a.active { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.progress-bar { height: 6px; border-radius: 3px; background: rgba(118,118,128,.16); overflow: hidden; min-width: 90px; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.thread { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 16px; background: rgba(118,118,128,.12); white-space: pre-wrap; }
.bubble.staff { align-self: flex-end; background: var(--accent-soft); }
.bubble small { display: block; color: var(--muted); margin-top: 4px; font-size: 11px; }
textarea.cell { min-height: 38px; width: 100%; }
code.key { font-size: 12px; color: var(--muted); }
dl.meta { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
dl.meta dt { color: var(--muted); font-size: 13px; }
dl.meta dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.phone { width: 300px; border: 10px solid #1d1d1f; border-radius: 40px; padding: 18px 14px 12px; background: linear-gradient(160deg, rgba(31,157,85,.12), rgba(0,113,227,.06)); display: flex; flex-direction: column; gap: 10px; }
.phone-title { font-size: 22px; font-weight: 700; }
.phone-card { background: rgba(255,255,255,.75); border-radius: 18px; padding: 12px; backdrop-filter: blur(8px); }
@media (prefers-color-scheme: dark) { .phone-card { background: rgba(44,44,46,.8); } }
.phone-btn { background: var(--accent); color: #fff; text-align: center; border-radius: 999px; padding: 10px; font-weight: 600; }
.phone-tabs { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; background: rgba(255,255,255,.6); border-radius: 999px; padding: 8px 12px; overflow: hidden; }
.phone-tabs span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
