@font-face {
  font-family: "MalintonMedium";
  src: url("/assets/fonts/MalintonMedium.otf") format("opentype");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "MalintonMedium";
  src: url("/assets/fonts/MalintonBold.otf") format("opentype");
  font-weight: 700 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --green: #558E62;
  --green-deep: #44754f;
  --ink: #2f5238;
  --muted: #7d9784;
  --line: rgba(85, 142, 98, 0.16);
  --line-strong: rgba(85, 142, 98, 0.32);
  --tint: rgba(85, 142, 98, 0.08);
  --cream: #f7f1de;
  --white: #ffffff;
  --danger: #a83832;
  --danger-bg: #f5e3df;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--cream);
  color: var(--ink);
  font-family: "MalintonMedium", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.no-scroll {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

button,
a {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* ---------- Shell ---------- */
.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--green);
  color: var(--white);
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-logo {
  height: 26px;
  width: auto;
  display: block;
}

.icon-btn {
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
}

.icon-btn:active {
  opacity: 0.6;
}

/* ---------- Side Menu ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background-color: rgba(31, 52, 37, 0.38);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease;
}

.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  width: 280px;
  max-width: 84vw;
  background-color: var(--green);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.36s var(--ease), visibility 0s linear 0.36s;
}

.side-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.36s var(--ease);
}

.drawer-head {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px;
}

.drawer-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 28px;
}

.drawer-item {
  width: 100%;
  min-height: 58px;
  padding: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.68);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-align: left;
  display: flex;
  align-items: center;
  opacity: 0;
  transform: translateX(16px);
  transition: color 0.2s ease, opacity 0.3s ease, transform 0.42s var(--ease);
}

.drawer-item.active,
.drawer-item:active {
  color: var(--white);
}

.drawer-item.active {
  font-weight: 700;
}

.drawer-footer {
  padding: 20px 28px 28px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.side-drawer.is-open .drawer-item,
.side-drawer.is-open .drawer-footer {
  opacity: 1;
  transform: translateX(0);
}

.side-drawer.is-open .drawer-item:nth-child(1) { transition-delay: 0s, 0.08s, 0.08s; }
.side-drawer.is-open .drawer-item:nth-child(2) { transition-delay: 0s, 0.12s, 0.12s; }
.side-drawer.is-open .drawer-item:nth-child(3) { transition-delay: 0s, 0.16s, 0.16s; }
.side-drawer.is-open .drawer-footer { transition-delay: 0.2s; }

.logout-form {
  margin: 0;
}

.drawer-signout {
  width: 100%;
  min-height: 46px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.drawer-signout:active {
  background-color: rgba(255, 255, 255, 0.12);
}

/* ---------- Page ---------- */
.main-content {
  flex: 1;
  padding: 40px 20px calc(48px + env(safe-area-inset-bottom));
}

.tab-panel {
  animation: fadeUp 0.32s var(--ease);
}

.page-head {
  text-align: center;
  margin-bottom: 28px;
}

.section-heading {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--green);
}

.page-sub {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.page-foot {
  margin-top: 28px;
  text-align: center;
}

.export-action {
  margin-top: 22px;
}

.export-btn {
  min-height: 48px;
}

.text-btn {
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.text-btn-danger {
  color: var(--danger);
  opacity: 0.75;
}

/* ---------- Filters ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.custom-dropdown {
  position: relative;
}

.dropdown-trigger {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  background-color: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.custom-dropdown.is-open .dropdown-trigger {
  background-color: var(--green);
  border-color: var(--green);
  color: var(--white);
}

.dropdown-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  padding: 6px;
  background-color: var(--cream);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.24s var(--ease), visibility 0s linear 0.24s;
}

.dropdown-menu::-webkit-scrollbar {
  display: none;
}

.custom-dropdown.is-open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.24s var(--ease);
}

.dropdown-option {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: block;
  transition: background-color 0.15s ease;
}

.dropdown-option:active {
  background-color: var(--tint);
}

@media (hover: hover) {
  .dropdown-option:hover {
    background-color: var(--tint);
  }
}

.dropdown-option.is-selected,
.dropdown-option.is-selected:hover {
  background-color: var(--green);
  color: var(--white);
}

.custom-date-wrap {
  margin-bottom: 12px;
  animation: fadeUp 0.24s var(--ease);
}

.range-date-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
  animation: fadeUp 0.24s var(--ease);
}

.date-pill-btn {
  position: relative;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.date-pill-btn:active {
  background-color: var(--tint);
  border-color: var(--green);
}

.date-pill-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.date-pill-text.is-placeholder {
  color: var(--muted);
}

.date-pill-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

.date-pill-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---------- Lists ---------- */
.menu-list {
  margin-top: 16px;
}

.empty-note {
  padding: 48px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.shift-item {
  border-bottom: 1px solid var(--line);
}

.shift-item:last-child {
  border-bottom: none;
}

.shift-row-btn {
  width: 100%;
  min-height: 66px;
  padding: 14px 0;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
}

.shift-left {
  min-width: 0;
  flex: 1;
}

.shift-name,
.user-name {
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shift-sub,
.user-sub {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.shift-right {
  flex-shrink: 0;
  text-align: right;
}

.shift-duration {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.shift-state,
.sync-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.shift-state::before,
.sync-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
  opacity: 0.5;
}

.shift-state.is-on,
.sync-label.is-synced {
  color: var(--green);
}

.shift-state.is-on::before,
.sync-label.is-synced::before,
.sync-label.is-failed::before {
  opacity: 1;
}

.sync-label.is-failed,
.shift-state.is-missed {
  color: var(--danger);
}

.shift-state.is-missed::before {
  opacity: 1;
}

/* Smooth expand / collapse */
.collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s var(--ease);
}

.collapse-inner {
  overflow: hidden;
  min-height: 0;
}

.shift-item.is-expanded .collapse,
.queue-section.is-open .collapse {
  grid-template-rows: 1fr;
}

.shift-punches {
  margin: 0 0 14px 2px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--line-strong);
}

.punch-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 14px;
}

.punch-time {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.punch-detail {
  font-size: 13px;
  color: var(--muted);
}

.punch-row.is-ignored {
  opacity: 0.45;
}

.punch-row.is-ignored .punch-time {
  text-decoration: line-through;
}

/* ---------- Users ---------- */
.device-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--danger);
  flex-shrink: 0;
}

.status-dot.is-online {
  background-color: var(--green);
}

.users-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.user-row:last-child {
  border-bottom: none;
}

.user-info {
  min-width: 0;
  flex: 1;
}

.user-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.user-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: -8px;
}

.link-action {
  min-height: 36px;
  padding: 0 8px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
}

.link-action-danger {
  color: var(--danger);
}

/* ---------- Device Queue ---------- */
.queue-section {
  margin-top: 32px;
  border-top: 1px solid var(--line);
}

.queue-toggle {
  width: 100%;
  min-height: 52px;
  padding: 0;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.queue-meta {
  min-width: 26px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background-color: var(--tint);
  color: var(--green);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.queue-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.queue-cmd-title {
  color: var(--ink);
}

.queue-cmd-sub {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.queue-status {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--green);
}

.queue-status.is-pending {
  color: var(--muted);
}

.queue-status.is-failed {
  color: var(--danger);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background-color: var(--green);
  border-color: var(--green);
  color: var(--white);
}

.btn-primary:active {
  background-color: var(--green-deep);
  border-color: var(--green-deep);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--line-strong);
  color: var(--green);
}

.btn-outline:active {
  background-color: var(--tint);
  border-color: var(--green);
}

.btn-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: var(--white);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Forms ---------- */
.field {
  margin-bottom: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.input,
.select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  background-color: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--ink);
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.2s ease;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--green);
}

.input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.input[readonly] {
  opacity: 0.6;
}

.input-pill {
  height: 44px;
  border-radius: 999px;
  text-align: center;
  background-color: transparent;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%237d9784' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.alert {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background-color: var(--danger-bg);
  color: var(--danger);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 60;
  width: max-content;
  max-width: calc(100% - 40px);
  padding: 12px 20px;
  border-radius: 999px;
  background-color: var(--ink);
  color: var(--cream);
  font-size: 14px;
  text-align: center;
  transform: translateX(-50%);
  animation: toastIn 0.32s var(--ease);
}

.toast.toast-error {
  background-color: var(--danger);
  color: var(--white);
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background-color: rgba(31, 52, 37, 0.38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.22s ease;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  background-color: var(--cream);
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheetUp 0.36s var(--ease);
}

@media (min-width: 520px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }

  .modal-sheet {
    border-radius: 20px;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 22px 6px;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
}

.btn-close {
  min-height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.modal-form,
.modal-body {
  padding: 14px 22px 24px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.delete-warning {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 4px 0;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--green);
}

/* ---------- Skeleton ---------- */
.skeleton-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.skeleton-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.skeleton-bar {
  display: block;
  height: 14px;
  border-radius: 999px;
  background-color: rgba(85, 142, 98, 0.14);
  animation: skeletonPulse 1.3s ease-in-out infinite;
}

.skeleton-bar.sm {
  height: 10px;
  background-color: rgba(85, 142, 98, 0.1);
}

.skeleton-bar.w-40 { width: 40%; }
.skeleton-bar.w-45 { width: 45%; }
.skeleton-bar.w-50 { width: 50%; }
.skeleton-bar.w-55 { width: 55%; }
.skeleton-bar.w-60 { width: 60%; }
.skeleton-bar.w-65 { width: 65%; }
.skeleton-bar.w-55px { width: 55px; }
.skeleton-bar.w-70px { width: 70px; }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100dvh;
}

.login-header {
  background-color: var(--green);
  padding: calc(48px + env(safe-area-inset-top)) 24px 40px;
  text-align: center;
}

.login-logo {
  height: 44px;
  width: auto;
  display: inline-block;
}

.login-main {
  padding: 40px 24px 48px;
}

.login-form {
  animation: fadeUp 0.36s var(--ease);
}

.login-submit {
  margin-top: 8px;
  min-height: 48px;
}

/* ---------- Motion ---------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes sheetUp {
  from { opacity: 0.6; transform: translateY(28px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes skeletonPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.42; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
