/* Fonts are served locally (vendor/, OFL): Inter for Latin text, Vazirmatn for Persian. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/vendor/inter/inter-latin-wght-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/vendor/vazirmatn/vazirmatn-arabic-wght-normal.woff2") format("woff2");
  /* Arabic script and the zero-width non-joiner, so Latin text stays in Inter. */
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}

/* Colours live in theme.css. */

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  font-family: "Inter", "Vazirmatn", system-ui, sans-serif;
  line-height: 1.45;
  /* Calories and weights line up in columns. */
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--text);
}

.sidebar {
  width: 180px;
  flex-shrink: 0;
  /* Window height, so the bottom items stay in view on long pages. */
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 16px 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
/* The sidebar brand links to the main page but doesn't look like a nav item. */
.sidebar .brand { padding: 4px 12px 16px; }
.sidebar .brand:hover { background: none; }
.brand img { width: 28px; height: 28px; }

.sidebar a, .sidebar button, .settings-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  font: inherit;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  background: none;
  cursor: pointer;
}

.icon { flex-shrink: 0; }
.sidebar a:hover, .sidebar button:hover, .settings-nav a:hover { background: var(--bg); }
.sidebar a.active, .settings-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
/* The login page has none. */
.sidebar[hidden] { display: none; }
/* Pushed to the end of the sidebar. */
.sidebar .bottom { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.sidebar #logout { color: var(--red); }

/* Settings has its own sidebar inside the main view. */
.settings { display: flex; gap: 16px; align-items: flex-start; }
.settings-content { flex: 1; min-width: 0; }
.settings-nav {
  width: 150px;
  flex-shrink: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
/* Group names such as "User" and "Admin" above their pages. */
.settings-nav h3 { margin: 8px 12px 0; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: var(--muted); }
/* The users table may run wider than other pages, and scrolls inside its card when it can't fit. */
main:has(.users) { max-width: 1200px; }
.users { overflow-x: auto; }
.users th, .users td { white-space: nowrap; }
.users th { padding: 0 0 6px; text-align: left; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.users th:nth-child(4) { text-align: right; }
.users .disabled td:first-child { color: var(--muted); }
.users .tag { margin-left: 6px; color: var(--muted); font-size: 0.85rem; }
td.toggle { width: 6.5em; text-align: right; padding-left: 12px; }
td.toggle button { margin: 0; }

main:has(.login) { margin: 0 auto; }
.login { max-width: 360px; margin: 10vh auto 0; }
.login .brand { padding: 4px 0 8px; }
.login .fields { grid-template-columns: 1fr; }

main { flex: 1; min-width: 0; padding: 16px 24px; max-width: 900px; }

.range { display: flex; justify-content: flex-end; margin-bottom: 16px; }
/* Pages that don't open with the range picker start as low as those that do (picker plus its margin). */
main > :first-child:not(.range, .login) { margin-top: 50px; }
.range select, .user-picker select {
  height: 34px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.range select:focus, .user-picker select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* The admin report's user and range pickers, side by side. */
.metrics-filters { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.metrics-filters .range { margin-bottom: 0; }
.metrics-filters select { max-width: 100%; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.tile span { font-size: 0.85rem; color: var(--muted); }
.tile strong { font-size: 1.6rem; font-weight: 700; }

/* The food log's chart column is only shown when there is room for it beside the log. */
.side { display: none; }
@media (min-width: 1280px) {
  main:has(.columns) { max-width: 1600px; }
  .columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .side { display: block; position: sticky; top: 16px; }
  .side .canvas { height: 420px; }
}

h2 { font-size: 1.1rem; font-weight: 650; display: flex; justify-content: space-between; align-items: baseline; }

/* Each day leads with its date on the left and a large total on the right. */
.day-head { margin: 4px 0 16px; display: flex; justify-content: space-between; align-items: baseline; }
.day-head p { margin: 0; }
.day-date, .day-total { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.day-total span { font-size: 1rem; font-weight: 500; letter-spacing: 0; color: var(--muted); }

.day, .chart {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.total, .time, .empty { color: var(--muted); font-weight: normal; }

table { width: 100%; border-collapse: collapse; }
/* Table cells treat height as a minimum; it keeps Latin and Persian rows equally tall. */
td { height: 40px; padding: 6px 0; border-top: 1px solid var(--border); vertical-align: middle; }
td.time { width: 60px; }
/* Fixed widths keep the share boxes and calories aligned across days. */
td.calories { width: 7em; text-align: right; white-space: nowrap; padding-left: 12px; }
td.share { width: 48px; text-align: right; padding-left: 12px; vertical-align: middle; }

.box {
  display: inline-block;
  width: 36px;
  height: 10px;
  border: 1px solid var(--muted);
  border-radius: 2px;
  vertical-align: middle;
}

.box span { display: block; height: 100%; background: var(--accent); }

.canvas { position: relative; height: 300px; }

.meter {
  position: relative;
  height: 18px;
  margin: 0;
  border: 1px solid var(--muted);
  border-radius: 3px;
  background: var(--bg);
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.15);
}

/* Glassy fill: a white sheen over the status colour. */
.meter .fill {
  height: 100%;
  border-radius: 2px;
  background-image: linear-gradient(to bottom, rgb(255 255 255 / 0.55), rgb(255 255 255 / 0.1) 50%, rgb(0 0 0 / 0.08));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.5), 0 1px 2px rgb(0 0 0 / 0.2);
}
.meter.under .fill { background-color: var(--green); }
.meter.between .fill { background-color: var(--amber); }
.meter.over .fill { background-color: var(--red); }

.meter .mark { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 1px; }
.meter .mark.losing { background: var(--green); }
.meter .mark.maintenance { background: var(--red); }

.meter-legend { margin: 10px 0 16px; font-size: 0.85rem; color: var(--muted); }
.meter-legend .losing { color: var(--green); }
.meter-legend .maintenance { color: var(--red); }

.entry { margin-bottom: 16px; }

.entry input, .form input, .form select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.entry input:focus, .form input:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.entry input:disabled { opacity: 0.6; }

.check {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.check p { margin: 4px 0; }
.check .suggestion { color: var(--muted); font-size: 0.9rem; }

.check button, .form button {
  margin: 4px 8px 4px 0;
  padding: 6px 14px;
  font: inherit;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.check button.secondary, .form button.secondary { color: var(--text); background: var(--bg); border: 1px solid var(--border); }

.form .fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px 12px; margin-bottom: 8px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.form input, .form select { font-size: 1rem; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.form .tabs button { margin: 0; color: var(--text); background: var(--bg); border: 1px solid var(--border); }
.form .tabs button.active { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }

td.actions { width: 5.5em; white-space: nowrap; text-align: right; padding-left: 12px; }
button.icon {
  display: inline-flex;
  padding: 5px;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
button.icon:hover { color: var(--accent); border-color: var(--accent); }
button.icon.delete { color: var(--red); }
button.icon.delete:hover { border-color: var(--red); }

.plan-current .losing, .calories.losing, #values .losing { color: var(--green); }
.plan-current .maintenance, .calories.maintenance, #values .maintenance { color: var(--red); }

.status { min-height: 1.2em; margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }
.status.error { color: var(--red); }

/* Medium screens: the sidebar collapses to an icon rail. */
@media (max-width: 900px) {
  .sidebar { width: 64px; padding: 16px 8px; align-items: center; }
  .sidebar span { display: none; }
  .sidebar a, .sidebar button { padding: 10px; }
  .sidebar .brand { padding: 4px 0 16px; }
}

@media (max-width: 600px) {
  body { flex-direction: column; }
  .sidebar {
    position: static;
    height: auto;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .bottom { margin-top: 0; margin-left: auto; flex-direction: row; }
  .settings { flex-direction: column; align-items: stretch; }
  .settings-nav { width: auto; flex-direction: row; }
  .settings-nav h3 { display: none; }
  .sidebar .brand { padding: 8px 12px; }
  main { padding: 16px; }
}
