:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: #dbe2ec;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-2: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--accent); }

nav { display: flex; align-items: center; }
nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 18px;
  font-size: 14px;
}
nav a:hover { color: var(--accent); }

/* Language switcher */
.lang-switch { display: inline-flex; gap: 4px; margin-left: 18px; }
.lang-switch button {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.lang-switch button:hover { color: var(--accent); }
.lang-switch button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.container { max-width: 1080px; margin: 0 auto; padding: 28px 24px; }

h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input, select {
  width: 100%;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.field { margin-bottom: 12px; }

button {
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 5px 10px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .value.green { color: var(--accent-2); }
.stat .value.blue { color: var(--accent); }

.progress { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent-2); }

.rec {
  background: #fff7ed;
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14px;
}

.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); }
.badge.admin { background: #fef3c7; color: #b45309; }

.muted { color: var(--muted); }
.right { text-align: right; }
.row-actions { display: flex; gap: 6px; }
.hidden { display: none; }
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 8px; font-size: 14px;
  border-left: 3px solid var(--accent-2);
  box-shadow: var(--shadow);
}
.footer { text-align: center; color: var(--muted); padding: 24px; font-size: 13px; }

/* Wide tables scroll horizontally instead of breaking the layout */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 560px; }

/* ---------- Responsive / mobile ---------- */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 12px 16px;
  }
  nav {
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    width: 100%;
  }
  nav a { margin-left: 0; font-size: 13px; }
  .lang-switch { margin-left: auto; }

  .container { padding: 20px 16px; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }
  .subtitle { margin-bottom: 18px; }
  .card { padding: 16px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* Stat value slightly smaller so long sums don't overflow */
  .stat .value { font-size: 21px; }

  /* Toast spans the bottom on small screens */
  .toast { left: 16px; right: 16px; bottom: 16px; }
}

@media (max-width: 400px) {
  .brand { font-size: 20px; }
  nav a { font-size: 12px; }
  .lang-switch button { padding: 3px 8px; }
}

/* Actual-value input in the "My metrics" table */
.actual-input { max-width: 120px; }

/* ---------- "My metrics" input table → cards on phones ---------- */
@media (max-width: 640px) {
  /* This table doesn't scroll on phones — it becomes stacked cards */
  #entries-table { min-width: 0; }
  #entries-table thead { display: none; }
  #entries-table,
  #entries-table tbody,
  #entries-table tr,
  #entries-table td { display: block; }

  #entries-table tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
  }

  #entries-table td {
    border: none;
    padding: 7px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: right;
  }

  /* Label from data-label on the left of each row */
  #entries-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    text-align: left;
    margin-right: 12px;
    flex: 0 0 auto;
  }

  /* Metric name = card title (no label, full width) */
  #entries-table td.cell-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin-bottom: 4px;
    text-align: left;
  }
  #entries-table td.cell-name::before { content: none; }

  #entries-table .actual-input { max-width: 160px; text-align: right; }
}
