:root {
  --bg: #0f172a;
  --bg2: #141f36;
  --card: #1c2a47;
  --card2: #243456;
  --line: #2e4166;
  --txt: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.35);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.35);
  --amber: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--txt);
  font-family: system-ui, -apple-system, "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 16px));
}

.app-wrapper {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ---------- Top Bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.brand small {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  font-weight: 800;
  font-size: 1.25rem;
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.clock {
  text-align: right;
  line-height: 1.15;
}

.clock #liveClock {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.clock small {
  color: var(--muted);
  font-size: 0.7rem;
  display: block;
}

/* ---------- Banners ---------- */
.banner {
  margin: 12px 14px 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.banner.warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

/* ---------- Main Content ---------- */
main {
  flex: 1;
  padding: 12px 14px 0;
  width: 100%;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: fadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.pill {
  background: var(--card2);
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
}

/* ---------- Punch Buttons ---------- */
.punch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.punch-btn {
  border: none;
  border-radius: 16px;
  padding: 16px 8px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: inherit;
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  min-height: 80px;
}

.punch-btn:active {
  transform: scale(0.96);
}

.punch-btn .big {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.1;
}

.punch-btn small {
  font-size: 0.74rem;
  font-weight: 500;
  opacity: 0.95;
}

.punch-btn.in {
  background: linear-gradient(135deg, #15803d, #22c55e);
  box-shadow: 0 4px 16px var(--green-glow);
}

.punch-btn.out {
  background: linear-gradient(135deg, #b91c1c, #ea580c);
  box-shadow: 0 4px 16px var(--red-glow);
}

.punch-btn.done {
  filter: saturate(0.3) brightness(0.75);
  box-shadow: none;
}

/* ---------- Form Controls ---------- */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type=text],
input[type=number],
input[type=time],
textarea,
select {
  width: 100%;
  max-width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type=time] {
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
}

textarea {
  resize: vertical;
  min-height: 64px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Row & Icon button */
.row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.row input {
  flex: 1;
  min-width: 0;
}

.btn-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  flex: 0 0 44px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--txt);
  padding: 0;
  touch-action: manipulation;
  transition: transform 0.08s, filter 0.15s;
}

.btn-icon:active {
  transform: scale(0.93);
  filter: brightness(1.2);
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--txt);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
  transition: background-color 0.12s, border-color 0.12s;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.chip.remove {
  background: #3a1d22;
  border-color: #7c2d3a;
  color: #fca5a5;
}

/* Switch & Checkbox */
.switch {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.84rem;
  color: var(--txt);
  background: var(--bg2);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.switch input {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  margin: 0;
  accent-color: var(--accent);
}

/* Summary Box */
.summary {
  background: var(--bg2);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.summary b {
  color: #fff;
  font-size: 0.95rem;
}

.summary .k {
  color: var(--muted);
  font-size: 0.72rem;
  display: block;
}

/* Action Buttons */
.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  width: 100%;
}

.actions.single {
  grid-template-columns: 1fr;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  touch-action: manipulation;
  transition: transform 0.08s ease, filter 0.15s ease;
  min-width: 0;
  line-height: 1.25;
}

.btn:active {
  transform: scale(0.97);
  filter: brightness(1.15);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn.ghost {
  background: var(--card2);
  color: var(--txt);
  border: 1px solid var(--line);
}

.btn.danger {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
}

.btn.file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.btn.file input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ---------- Month Tab ---------- */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.month-nav h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
  letter-spacing: 0.02em;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 0;
}

.stat .v {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat .k {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 2px;
}

.stat.green .v { color: var(--green); }
.stat.amber .v { color: var(--amber); }
.stat.red .v { color: var(--red); }

/* Day List */
.day-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.day.sat { border-left: 4px solid #3b82f6; }
.day.sun { border-left: 4px solid var(--red); }
.day.holiday { border-left: 4px solid var(--amber); }

.day-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.day-num {
  width: 32px;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
}

.day-wd {
  width: 26px;
  font-size: 0.76rem;
  color: var(--muted);
  flex-shrink: 0;
}

.day-main {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-main .ph { color: var(--muted); }
.day-main .nt { color: var(--muted); font-size: 0.78rem; margin-left: 4px; }
.day-empty { color: var(--muted); font-size: 0.82rem; }

.day-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.day.open .day-body {
  display: block;
}

.day-body .grid2 {
  margin-top: 12px;
}

.day-body .field {
  margin-bottom: 12px;
}

/* ---------- Bottom Navigation Bar ---------- */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 12px calc(env(safe-area-inset-bottom, 8px) + 6px);
  max-width: 480px;
  margin: 0 auto;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.tab .tab-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: stroke 0.15s ease, transform 0.15s ease;
}

.tab .tab-title {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.1;
}

.tab .tab-sub {
  font-size: 0.62rem;
  font-weight: 500;
  opacity: 0.75;
}

.tab.active {
  color: var(--accent);
}

.tab.active .tab-icon {
  transform: translateY(-1px);
}

.tab:active {
  transform: scale(0.92);
}

/* ---------- Toast Message ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom, 16px));
  transform: translateX(-50%);
  background: rgba(11, 18, 32, 0.95);
  border: 1px solid var(--line);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  max-width: calc(100vw - 32px);
  width: max-content;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ---------- Salary Dashboard & Legal Rates ---------- */
.salary-card {
  background: linear-gradient(145deg, #1b2844 0%, #152037 100%);
  border: 1px solid #3b82f64d;
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.4);
}

.salary-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.salary-header small {
  color: var(--muted);
  font-size: 0.76rem;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.salary-header h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #e2e8f0;
}

.salary-amount {
  font-variant-numeric: tabular-nums;
  font-size: 2.1rem;
  font-weight: 800;
  color: #38bdf8;
  letter-spacing: -0.02em;
  margin-bottom: 14px;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.salary-amount .currency {
  font-size: 1.3rem;
  font-weight: 600;
  color: #94a3b8;
}

.salary-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid #2e416680;
}

.salary-item {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}

.salary-item .k {
  color: var(--muted);
  font-size: 0.72rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.salary-item .v {
  font-variant-numeric: tabular-nums;
  font-size: 0.98rem;
  font-weight: 700;
  color: #f8fafc;
}

.salary-item .sub {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: normal;
  display: block;
}

.rate-badge {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
}

.rate-badge.green {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.3);
}

.rate-badge.amber {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.rate-badge.red {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Places Manager */
.place-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.place-card-item {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.place-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.place-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.place-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

.place-card-meta b {
  color: #38bdf8;
}

.place-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}

