:root {
  --ink: #1c2430;
  --muted: #5c6b7a;
  --line: #d7dee6;
  --paper: #f4f1ea;
  --white: #fff;
  --navy: #1b365d;
  --navy-2: #152a48;
  --gold: #b08d2e;
  --green: #1f7a4d;
  --red: #a33b32;
  --shadow: 0 10px 30px rgba(21, 42, 72, 0.12);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Segoe UI", Calibri, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  overscroll-behavior: contain;
}
button, a, input, select, label { touch-action: manipulation; }
button, input, select { font: inherit; font-size: 16px; }
button { cursor: pointer; -webkit-tap-highlight-color: rgba(176, 141, 46, 0.25); }

.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-t)) 16px max(16px, var(--safe-b));
  background: radial-gradient(circle at top, #2a4d82, var(--navy-2));
}
.login-card {
  width: min(420px, 100%);
  background: var(--white);
  padding: 28px 22px 32px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  border-top: 6px solid var(--gold);
}
.logo-nura {
  margin: 8px 0 28px;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--navy);
  line-height: 1;
}
.login-card h1 { margin: 6px 0 0; font-family: Georgia, serif; color: var(--navy); }
.kicker { margin: 0; color: var(--gold); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.sub { color: var(--muted); margin: 0 0 24px; }
.login-card label { display: grid; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.login-card input, .field input, .field select, table input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
}
.login-card button, .btn {
  background: var(--navy);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  min-height: 44px;
}
.login-card button { width: 100%; margin-top: 8px; }
.btn.gold { background: var(--gold); color: #1c1608; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn.danger { background: var(--red); }
.error { color: var(--red); font-size: 14px; }

.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: var(--navy-2);
  color: #e8eef6;
  font-weight: 600;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  color: inherit;
  font-size: 22px;
  line-height: 1;
}
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 20, 32, 0.45);
  z-index: 45;
}

.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  background: var(--navy-2);
  color: #e8eef6;
  display: flex;
  flex-direction: column;
  padding: 20px 14px calc(16px + var(--safe-b));
}
.brand { display: flex; gap: 10px; align-items: center; padding: 8px 8px 20px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--gold); color: #1c1608; font-weight: 700;
}
.brand small { display: block; color: #b9c6d6; }
.sidebar nav { display: grid; gap: 6px; flex: 1; }
.sidebar a {
  color: inherit; text-decoration: none; padding: 12px;
  border-radius: 8px; min-height: 44px; display: flex; align-items: center;
}
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,0.08); }
.sidebar-foot { padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
#who { display: block; font-size: 13px; color: #b9c6d6; word-break: break-word; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.row-actions .btn { padding: 8px 10px; min-height: 40px; font-size: 13px; }
table.data input.name-in {
  width: 120px;
  min-height: 40px;
  text-align: left;
  padding: 6px 8px;
}
.sidebar-foot button {
  margin-top: 8px; width: 100%; background: transparent; color: #e8eef6;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 10px;
  min-height: 44px;
}

.main {
  padding: 28px 32px calc(48px + var(--safe-b));
  padding-left: max(32px, var(--safe-l));
  padding-right: max(32px, var(--safe-r));
  min-width: 0;
}
.top h1 { margin: 0; font-family: Georgia, serif; color: var(--navy); }
.top p { margin: 6px 0 22px; color: var(--muted); }

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.8);
  min-width: 0;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.field { display: grid; gap: 6px; font-size: 14px; min-width: min(220px, 100%); flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 0 -4px 8px;
}
.swipe-hint { display: none; font-size: 12px; color: var(--muted); margin: 0 0 8px; }

table.data { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 14px; }
table.data.compact { min-width: 0; width: auto; max-width: 100%; }
table.data.compact th:not(.left),
table.data.compact td:not(.left) {
  width: 1%;
  white-space: nowrap;
}
table.data th, table.data td { border: 1px solid var(--line); padding: 8px; text-align: center; }
table.data th { background: #eef3f8; color: var(--navy); }
table.data td.left, table.data th.left { text-align: left; }
table.data input {
  width: 72px;
  min-height: 44px;
  text-align: center;
  padding: 8px;
}
table.data input[readonly] {
  background: #eef3f8;
  color: var(--ink);
}
table.data tfoot td { font-weight: 700; background: #f7f1e3; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.section-title {
  font-family: Georgia, serif;
  color: var(--navy);
  font-size: 1.15rem;
  margin: 8px 0 12px;
}
.ok { color: var(--green); font-weight: 600; }

#toast {
  position: fixed;
  right: max(16px, var(--safe-r));
  bottom: max(16px, var(--safe-b));
  left: auto;
  background: var(--navy); color: #fff; padding: 12px 16px;
  border-radius: 10px; box-shadow: var(--shadow);
  max-width: min(360px, calc(100vw - 32px));
  z-index: 50;
}

.user-perms { display: flex; gap: 14px; flex-wrap: wrap; }
.user-perms label { display: flex; gap: 8px; align-items: center; min-height: 44px; }
.user-perms input { width: 20px; height: 20px; min-height: 20px; }
.perm-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.perm-groups fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0;
  padding: 10px 14px 12px;
  background: #f7fafc;
}
.perm-groups legend {
  font-weight: 700;
  color: var(--navy);
  padding: 0 6px;
}
.perm-groups label {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 40px;
}
.perm-groups fieldset.perm-daily {
  background: #eef5ee;
  border-color: #c5d9c8;
}
.perm-groups fieldset.perm-daily p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}
.daily-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.perm-groups input,
table.data td.perm-cell input {
  width: 20px;
  height: 20px;
  min-height: 20px;
}

@media (max-width: 900px) {
  .mobile-bar { display: flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 96px; }
  .swipe-hint { display: block; }
  table.data { font-size: 13px; }
  .toolbar .btn, .toolbar .field { width: 100%; }
  .toolbar .btn { text-align: center; }
  .daily-actions {
    position: fixed;
    left: max(12px, var(--safe-l));
    right: max(12px, var(--safe-r));
    bottom: max(12px, var(--safe-b));
    z-index: 30;
    width: auto;
  }
  .daily-actions .btn { flex: 1; text-align: center; }
  #toast { bottom: max(72px, calc(var(--safe-b) + 60px)); left: 16px; right: 16px; max-width: none; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    padding-top: calc(16px + var(--safe-t));
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open .nav-backdrop { display: block; }
  body.menu-open { overflow: hidden; }
}

@media (max-width: 480px) {
  .top h1 { font-size: 1.35rem; }
  .card { padding: 14px; }
  table.data input { width: 64px; }
}
