:root {
  --navy: #0C056D;
  --navy-2: #1a1290;
  --navy-soft: #eceaf8;
  --yellow: #FFEC29;
  --yellow-soft: #fffbd6;
  --white: #ffffff;
  --bg: #f5f5fa;
  --text: #16133a;
  --muted: #6b6889;
  --line: #e2e0ef;
  --green: #0f8a4f;
  --green-soft: #e3f6ec;
  --red: #c62828;
  --red-soft: #fdeaea;
  --orange: #b86200;
  --orange-soft: #fff1de;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(12, 5, 109, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  background: var(--navy);
  color: var(--white);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--yellow); color: var(--navy);
  display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none;
}
.brand-text { line-height: 1.2; min-width: 0; }
.brand-text strong { display: block; font-size: 17px; }
.brand-text span { font-size: 13px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.icon-btn {
  background: rgba(255, 255, 255, 0.12); color: var(--white); border: 0;
  border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.2); }

.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- Status hero ---------- */
.status-hero {
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.status-hero::after {
  content: ""; position: absolute; inset-inline-start: -30px; bottom: -40px;
  width: 140px; height: 140px; border-radius: 50%; background: var(--yellow); opacity: 0.12;
}
.status-hero .hello { font-size: 15px; opacity: 0.85; }
.status-hero .state { font-size: 26px; font-weight: 800; margin: 4px 0; display: flex; align-items: center; gap: 10px; }
.status-hero .meta { font-size: 14px; opacity: 0.85; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #9a97b8; display: inline-block; flex: none; }
.dot.in_office { background: #36d27f; }
.dot.in_meeting { background: var(--yellow); }
.dot.after_meeting { background: #ffb547; }
.dot.out { background: #9a97b8; }

/* ---------- Big actions ---------- */
.actions { display: grid; gap: 12px; margin-bottom: 16px; }
.action {
  display: flex; align-items: center; gap: 14px;
  width: 100%; border: 0; border-radius: var(--radius);
  padding: 18px; cursor: pointer; text-align: start;
  font-size: 18px; font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, opacity 0.2s;
}
.action:active { transform: scale(0.98); }
.action:disabled { opacity: 0.55; cursor: progress; }
.action .ic {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; flex: none;
}
.action small { display: block; font-weight: 500; font-size: 13px; opacity: 0.75; }
.action.primary { background: var(--navy); color: var(--white); }
.action.primary .ic { background: var(--yellow); color: var(--navy); }
.action.accent { background: var(--yellow); color: var(--navy); }
.action.accent .ic { background: var(--navy); color: var(--yellow); }
.action.plain { background: var(--white); color: var(--navy); border: 2px solid var(--navy-soft); }
.action.plain .ic { background: var(--navy-soft); }
.action.danger { background: var(--white); color: var(--red); border: 2px solid var(--red-soft); }
.action.danger .ic { background: var(--red-soft); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 14px; margin: 12px 0 6px; }
.field, select.field, textarea.field {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--white); font-size: 16px; outline: none;
}
.field:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(12, 5, 109, 0.12); }
textarea.field { min-height: 110px; resize: vertical; }
.ltr { direction: ltr; text-align: right; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  margin: 0; text-align: center; padding: 12px 8px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--white); font-weight: 600; font-size: 15px;
}
.seg input:checked + label { border-color: var(--navy); background: var(--navy); color: var(--white); }
.seg input:focus-visible + label { box-shadow: 0 0 0 3px rgba(12, 5, 109, 0.25); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; cursor: pointer; font-size: 16px;
}
.btn.block { width: 100%; }
.btn.primary { background: var(--navy); color: var(--white); }
.btn.accent { background: var(--yellow); color: var(--navy); }
.btn.ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn.danger { background: var(--red); color: var(--white); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px 16px;
  background: var(--navy);
}
.login-box { width: 100%; max-width: 400px; background: var(--white); border-radius: 20px; padding: 28px 22px; }
.login-logo { display: block; max-width: 180px; width: 60%; margin: 0 auto 8px; }
.login-box h1 { text-align: center; font-size: 20px; margin: 4px 0 2px; }
.login-box p.sub { text-align: center; margin: 0 0 12px; color: var(--muted); font-size: 14px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start;
}
.timeline li:last-child { border-bottom: 0; }
.timeline .t { font-weight: 700; min-width: 72px; color: var(--navy); font-size: 14px; }
.timeline .d { flex: 1; font-size: 15px; }
.timeline .d small { display: block; color: var(--muted); font-size: 13px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--navy-soft); color: var(--navy); white-space: nowrap;
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.yellow { background: var(--yellow-soft); color: #6d5f00; }
.flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

/* ---------- Notice ---------- */
.notice { border-radius: var(--radius); padding: 16px; margin-bottom: 16px; font-size: 15px; }
.notice.warn { background: var(--orange-soft); color: #6b3a00; }
.notice.info { background: var(--navy-soft); color: var(--navy); }
.notice.err { background: var(--red-soft); color: #7a1414; }

/* ---------- Sheet (modal) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(12, 5, 60, 0.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--white); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up 0.2s ease;
}
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--white); padding: 12px 18px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); width: max-content; z-index: 200;
  transition: all 0.25s ease; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

.spinner {
  width: 22px; height: 22px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: currentColor;
  border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; min-height: 60vh; color: var(--navy); }
.center-load .spinner { width: 36px; height: 36px; border-color: var(--navy-soft); border-top-color: var(--navy); }

/* =================== Admin =================== */
.admin .wrap { max-width: 1200px; }
.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px; background: var(--white);
  border-bottom: 1px solid var(--line); position: sticky; top: 60px; z-index: 40;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 700; color: var(--muted); white-space: nowrap; font-size: 15px; position: relative;
}
.tab.active { background: var(--navy); color: var(--white); }
.tab .count {
  background: var(--red); color: var(--white); border-radius: 999px; font-size: 11px; padding: 0 6px; margin-inline-start: 4px;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--white); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 800; color: var(--navy); line-height: 1.2; }
.stat .l { font-size: 14px; color: var(--muted); }
.stat.hl { background: var(--navy); }
.stat.hl .n { color: var(--yellow); }
.stat.hl .l { color: rgba(255, 255, 255, 0.8); }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 960px) { .grid-2 { grid-template-columns: 1.1fr 0.9fr; } }

.people { display: grid; gap: 10px; }
.person {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--white);
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--navy-soft); color: var(--navy);
  display: grid; place-items: center; font-weight: 800; flex: none;
}
.person .info { flex: 1; min-width: 0; }
.person .name { font-weight: 700; }
.person .sub { font-size: 13px; color: var(--muted); }

#map, #officeMap { height: 420px; border-radius: var(--radius); overflow: hidden; z-index: 1; }
#officeMap { height: 300px; margin-top: 12px; }

.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); background: var(--white); }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--navy-soft); color: var(--navy); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.fb { max-width: 340px; white-space: pre-wrap; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; margin-bottom: 12px; }
.filters label { margin-top: 0; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; margin: 12px 0; }
.switch input { width: 48px; height: 28px; appearance: none; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: 0.2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--white); transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { inset-inline-start: 23px; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

@media (max-width: 480px) {
  .status-hero .state { font-size: 22px; }
  .action { font-size: 17px; padding: 16px; }
}
