/* Ubuntu 3.0 — base styles, mobile-first */
:root {
  --brand: #B73B3F;
  --brand-dark: #8C2D31;
  --brand-tint: #FBEDED;
  --bg: #F7F7F8;
  --card: #FFFFFF;
  --text: #1B1B1B;
  --muted: #6B6B6B;
  --border: #E6E6E8;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.05);
  --success: #2D8659;
  --warning: #B7791F;
  --danger: #B73B3F;
  --radius: 14px;
  --tabbar-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand);
  color: #fff;
  padding-top: var(--safe-top);
}
.app-header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}
.app-header__title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header__status { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: transparent;
  border: 0;
  color: #fff;
  padding: 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.net-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255,255,255,.4);
  display: inline-block;
}
.net-dot.offline { background: #ffd75e; box-shadow: 0 0 0 2px rgba(255,255,255,.4); }

/* ---------- sync button ---------- */
.sync-btn {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 0;
  border-radius: 999px;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.sync-btn:active { background: rgba(255,255,255,.28); }
.sync-btn[data-state="syncing"] .sync-icon { animation: sync-spin 1.1s linear infinite; }
.sync-btn[data-state="error"]    { background: rgba(255,255,255,.18); color: #FFD0CE; }
.sync-btn[data-state="offline"]  { color: #FFE89A; }
.sync-btn[data-state="idle"]     { color: #FFFFFF; }
@keyframes sync-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ---------- language switcher ---------- */
.lang-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  cursor: pointer;
  min-height: 32px;
}
.lang-btn:active { background: rgba(255,255,255,.28); }
.lang-btn[aria-expanded="true"] { background: rgba(255,255,255,.28); }
.lang-btn__code { line-height: 1; }

.lang-menu {
  position: absolute;
  right: 12px;
  top: calc(var(--header-h) + var(--safe-top) - 4px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border: 1px solid var(--border);
  min-width: 180px;
  overflow: hidden;
  z-index: 30;
}
.lang-menu__item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: #fff;
  color: var(--text);
  border: 0;
  padding: 12px 14px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  min-height: 44px;
}
.lang-menu__item:hover { background: #F4F4F6; }
.lang-menu__item:active { background: var(--brand-tint); }
.lang-menu__item[aria-current="true"] {
  color: var(--brand);
  font-weight: 600;
}
.lang-menu__code {
  display: inline-block;
  min-width: 28px;
  padding: 2px 6px;
  background: var(--brand-tint);
  color: var(--brand-dark);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .4px;
}
.lang-menu__item[aria-current="true"] .lang-menu__code {
  background: var(--brand);
  color: #fff;
}

/* ---------- main view ---------- */
.view {
  padding: 16px;
  padding-bottom: calc(var(--tabbar-h) + 24px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 9;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  gap: 2px;
  padding: 6px 0;
}
.tab[aria-current="page"] { color: var(--brand); }
.tab span { line-height: 1; }

/* ---------- typography & utility ---------- */
h2 { font-size: 20px; margin: 8px 0 12px; }
h3 { font-size: 16px; margin: 8px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.spacer { height: 12px; }
.spacer-lg { height: 20px; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
}
.btn:active { background: var(--brand-dark); }
.btn--ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
}
.btn--ghost:active { background: var(--brand-tint); }
.btn--soft {
  background: var(--brand-tint);
  color: var(--brand-dark);
}
.btn--danger { background: var(--danger); }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card__title { font-weight: 600; font-size: 16px; margin: 0 0 4px; }
.card__sub { color: var(--muted); font-size: 13px; }
.card-link {
  display: block; text-decoration: none; color: inherit;
}
.card-link:active .card { background: #FAFAFA; }

/* dashboard tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.tile__label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.tile__value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.tile__sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.tile--wide { grid-column: span 2; }

.bar { background: #EEE; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar__fill { background: var(--brand); height: 100%; }

/* ---------- login logo block ---------- */
.login-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 0 16px;
  margin: 0 -2px;
}
.login-logo img {
  display: block;
  max-width: 60%;
  max-height: 180px;
  height: auto;
  width: auto;
}

/* ---------- forms ---------- */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
.form-group textarea { min-height: 96px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--brand);
}
.checkbox {
  display: flex; align-items: center; gap: 8px;
}
.checkbox input { width: 20px; height: 20px; accent-color: var(--brand); }

/* ---------- list rows ---------- */
.list { display: flex; flex-direction: column; gap: 0; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.list-item__title { font-weight: 600; }
.list-item__sub { color: var(--muted); font-size: 13px; }
.list-item .grow { min-width: 0; }
.list-item__title, .list-item__sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toggle {
  appearance: none;
  width: 44px; height: 26px;
  background: #ddd;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background .15s;
}
.toggle:checked { background: var(--success); }
.toggle::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: #fff; border-radius: 50%;
  transition: transform .15s;
}
.toggle:checked::after { transform: translateX(18px); }

/* ---------- empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}
.empty h3 { margin: 8px 0 4px; color: var(--text); }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: 16px;
  bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom));
  background: var(--brand); color: #fff;
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 0;
  box-shadow: 0 4px 16px rgba(183,59,63,.35);
  cursor: pointer;
  z-index: 8;
}
.fab:active { background: var(--brand-dark); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1B1B1B; color: #fff;
  padding: 10px 14px; border-radius: 999px;
  font-size: 14px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* ---------- thumbnails ---------- */
.thumb {
  width: 56px; height: 56px;
  background: #eee;
  border-radius: 10px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- pills ---------- */
.pill {
  display: inline-block;
  padding: 2px 8px;
  background: var(--brand-tint);
  color: var(--brand-dark);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill--muted { background: #EEE; color: var(--muted); }
.pill--success { background: #DDEEE3; color: #1E5C3D; }

/* ---------- attendance row ---------- */
.att-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}

/* ---------- responsive ---------- */
@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile--wide { grid-column: span 3; }
}
