:root {
  --bg: #f2f4f8;
  --bg-accent: #e8ecf4;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --text: #1b2a41;
  --muted: #63758f;
  --brand: #204a83;
  --brand-strong: #17345d;
  --plum: #4B2E6D;
  --accent: #f39b12;
  --accent-soft: #ffe8bd;
  --danger: #bf3d3d;
  --success: #1e8a57;
  --border: #cfdae9;
  --border-strong: #b5c4da;
  --ring: #7fa4d8;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 4px 16px rgba(22, 43, 73, 0.08);
  --shadow: 0 12px 34px rgba(22, 43, 73, 0.1);
  --shadow-lg: 0 20px 44px rgba(30, 22, 44, 0.16);
  --trans: 0.18s ease;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: "Manrope", "Noto Sans", "Segoe UI", sans-serif;
  line-height: 1.45;
  background:
    radial-gradient(920px 420px at 82% -10%, rgba(75, 46, 109, 0.22) 0%, transparent 64%),
    radial-gradient(1000px 520px at 12% -12%, rgba(75, 46, 109, 0.08) 0%, transparent 60%),
    linear-gradient(180deg, #f9f6fd 0%, #f5f2fa 48%, var(--bg) 100%);
}

.container {
  width: min(1240px, 95vw);
  margin: 0 auto;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -46px;
  z-index: 200;
  background: var(--brand);
  color: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(7px);
  background: linear-gradient(180deg, #5a3a81 0%, #6a4792 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 22px rgba(75, 46, 109, 0.22);
}

.header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.brand {
  font-size: clamp(17px, 2vw, 22px);
  font-weight: 800;
  letter-spacing: 0.2px;
  color: #fff;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: thin;
}

.nav a {
  text-decoration: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  transition: background var(--trans), color var(--trans), border-color var(--trans), transform var(--trans);
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.20);
  border-color: rgba(255, 255, 255, 0.40);
}

.nav a.is-active,
.nav a[aria-current="page"] {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.nav form {
  margin: 0 0 0 2px;
}

.nav .btn {
  min-height: 34px;
  font-size: 13px;
  border-radius: 999px;
}

.main {
  padding: 24px 0 48px;
}

.card {
  background:
    radial-gradient(420px 180px at 100% 0%, rgba(106, 71, 146, 0.07) 0%, transparent 65%),
    linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  border: 1px solid #c7d4e8;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 16px;
  transition: transform var(--trans), box-shadow var(--trans), border-color var(--trans);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(22, 43, 73, 0.13);
  border-color: #b7c7df;
}

.compact-card {
  margin-bottom: 0;
}

h1, h2, h3 {
  margin: 0 0 10px;
  line-height: 1.2;
  color: #17263f;
}

h1 {
  font-size: clamp(24px, 3.4vw, 36px);
  letter-spacing: -0.02em;
  position: relative;
}
h1::after {
  content: "";
  display: block;
  width: 66px;
  height: 4px;
  margin-top: 9px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6a4792 0%, #4B2E6D 100%);
}
h2 { font-size: clamp(19px, 2.4vw, 24px); }
h3 { font-size: clamp(15px, 2vw, 18px); }

p { margin: 0 0 10px; }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select, button, textarea {
  width: 100%;
  display: block;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #b8c8df;
  border-radius: var(--radius-sm);
  background: #fff;
  color: #1c2d48;
  font-size: 15px;
  line-height: 1.25;
}

input, select, button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

input::placeholder,
textarea::placeholder {
  color: #9ba9bc;
}

input:focus,
select:focus,
textarea:focus,
button:focus,
a:focus,
[tabindex]:focus {
  outline: 3px solid rgba(127,164,216,0.35);
  outline-offset: 1px;
  border-color: #8d66ba;
  box-shadow: 0 0 0 4px rgba(75, 46, 109, 0.12);
}

input[required],
select[required],
textarea[required] {
  background-image: linear-gradient(to right, transparent calc(100% - 8px), #f3b854 calc(100% - 8px));
  background-repeat: no-repeat;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: #d17272;
}

.input-error {
  border-color: #d17272 !important;
  background: #fff6f6;
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  height: 18px;
  display: inline-block;
  padding: 0;
  border-radius: 4px;
  appearance: auto;
}

input[type="number"] {
  appearance: auto;
  -moz-appearance: textfield;
}

.scanner {
  font-size: 28px;
  letter-spacing: 1px;
  padding: 12px;
  font-weight: 700;
}

.btn {
  border: 1px solid transparent;
  width: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 800;
  font-size: 14px;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 12px;
  transition: transform var(--trans), filter var(--trans), background var(--trans), border-color var(--trans), color var(--trans);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #6a4792 0%, #4B2E6D 100%);
  color: #fff;
  box-shadow: 0 10px 18px rgba(75, 46, 109, 0.26);
}

.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(180deg, #cc4e4e 0%, var(--danger) 100%);
  color: #fff;
  box-shadow: 0 10px 16px rgba(191, 61, 61, 0.22);
}

.btn-danger:hover {
  filter: brightness(1.03);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--brand);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: #edf2fa;
}

.inline { display: flex; gap: 10px; align-items: end; }
.inline-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.scanner-prefs {
  margin-top: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.scanner-prefs label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #3a557c;
}

.empty-state {
  border: 1px dashed #c8d6ea;
  border-radius: 12px;
  background: linear-gradient(180deg, #fbfdff 0%, #f4f8ff 100%);
  padding: 14px;
}

.empty-state-title {
  font-weight: 800;
  margin-bottom: 4px;
  color: #233c63;
}

.skeleton-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.skeleton-line {
  height: 11px;
  border-radius: 999px;
  background: linear-gradient(90deg, #edf2fa 0%, #dfe8f6 50%, #edf2fa 100%);
  background-size: 240% 100%;
  animation: skeletonShimmer 1.15s linear infinite;
}

.skeleton-line:nth-child(2) { width: 92%; }
.skeleton-line:nth-child(3) { width: 78%; }

@keyframes skeletonShimmer {
  from { background-position: 0 0; }
  to { background-position: 220% 0; }
}

.sticky-action-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.card form .grid-2,
.card form .grid-3 {
  margin-bottom: 10px;
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #c1cfe5;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.table th,
.table td {
  border-bottom: 1px solid #dce4f1;
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 14px;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, #eef3fc 0%, #e8effa 100%);
  color: #4b6183;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.table tbody tr:nth-child(even) {
  background: #fafbfd;
}

.table tbody tr:hover {
  background: #f1f6ff;
}

.table img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #c9d4e6;
  background: #fff;
}

.attendance-list {
  display: grid;
  gap: 12px;
}

.attendance-card {
  border: 1px solid #d7e0ef;
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
  box-shadow: 0 8px 20px rgba(22, 43, 73, 0.06);
  padding: 14px;
}

.attendance-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.attendance-name {
  font-weight: 800;
  font-size: 16px;
  color: #182844;
}

.attendance-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.attendance-radio {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.attendance-option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #c8d4e4;
  background: #f8fbff;
  color: #4b6183;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform var(--trans), background var(--trans), border-color var(--trans), color var(--trans), box-shadow var(--trans);
}

.attendance-option:hover {
  transform: translateY(-1px);
  border-color: #9fb1cc;
  background: #eef4ff;
}

.attendance-radio:focus-visible + .attendance-option {
  outline: 3px solid rgba(127,164,216,0.35);
  outline-offset: 2px;
}

.attendance-radio:checked + .attendance-option {
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(75, 46, 109, 0.18);
}

.attendance-option-success,
.attendance-radio:checked + .attendance-option-success {
  background: linear-gradient(180deg, #2a9d6f 0%, #1e8a57 100%);
}

.attendance-option-danger,
.attendance-radio:checked + .attendance-option-danger {
  background: linear-gradient(180deg, #d15b5b 0%, #bf3d3d 100%);
}

.attendance-option-warning,
.attendance-radio:checked + .attendance-option-warning {
  background: linear-gradient(180deg, #f1a93a 0%, #d98c12 100%);
}

.attendance-comment {
  margin-top: 12px;
}

.attendance-select-wrap {
  display: grid;
  gap: 6px;
}

.attendance-select {
  min-height: 52px;
  border-radius: 14px;
  font-weight: 800;
  background: #f8fbff;
}

.attendance-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.flash {
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  animation: flashIn 220ms ease;
  box-shadow: 0 8px 18px rgba(31, 45, 64, 0.08);
}

@keyframes flashIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.flash-error { background: #fff2f2; border-color: #f0c6c6; color: #8f2f2f; }
.flash-success { background: #edf9f2; border-color: #c6e8d4; color: #216444; }
.flash-info { background: #eef4ff; border-color: #cdddfa; color: #274c80; }

.muted { color: var(--muted); }

.login-wrap {
  min-height: 80vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(520px, 92vw);
}

.link-btn {
  width: auto;
  border: 0;
  background: transparent;
  color: #47648f;
  text-decoration: underline;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.link-btn.danger { color: var(--danger); }

.settings-form input,
.settings-form select {
  background: #fff !important;
  border: 1px solid var(--border-strong) !important;
  color: #132540 !important;
  min-height: 44px !important;
}

.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.settings-checkbox-row input[type="checkbox"] {
  width: 18px !important;
  height: 18px !important;
  min-height: 18px !important;
  margin: 0;
}

.settings-checkbox-row label { margin: 0; }
.settings-actions { margin-top: 14px; }
.settings-actions .btn { min-width: 180px; }

.print-mode-preview {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.print-sample {
  border: 1px dashed #b8c7de;
  border-radius: 12px;
  background:
    radial-gradient(260px 120px at 100% 0%, rgba(75, 46, 109, 0.09) 0%, transparent 68%),
    linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  padding: 10px;
}

.print-sample h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

.preview-a4 {
  aspect-ratio: 210 / 297;
  background: #fff;
  border: 1px solid #d8e1ef;
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px;
}

.preview-a4 div,
.preview-scroll div {
  border: 1px solid #c9d8ef;
  border-radius: 4px;
  background: #f4f8ff;
}

.preview-scroll {
  height: 120px;
  background: repeating-linear-gradient(180deg, #fff 0 16px, #f5f8fd 16px 32px);
  border: 1px solid #d8e1ef;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.pwa-update-banner,
.pwa-install-banner {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 14000;
  background: #1f3e6b;
  color: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  width: min(92vw, 560px);
}

.pwa-update-banner { bottom: 16px; }
.pwa-install-banner { bottom: 74px; }

.pwa-banner-actions {
  display: inline-flex;
  gap: 8px;
  margin-left: 8px;
}

.pwa-btn {
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-weight: 700;
}

.pwa-btn.primary {
  background: #fff;
  color: #1f3e6b;
}

.pwa-btn.ghost {
  background: #315788;
  color: #fff;
}

@media (max-width: 980px) {
  .grid-2, .grid-3, .print-mode-preview { grid-template-columns: 1fr; }
  .inline { flex-direction: column; align-items: stretch; }
  .btn { width: 100%; }

  .header {
    position: static;
  }

  .header-inner {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-bottom: 72px;
  }

  .brand {
    white-space: normal;
  }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: #f6f9ff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 22px rgba(20, 35, 60, 0.13);
    gap: 8px;
  }

  .nav a {
    color: var(--brand);
    background: #ffffff;
    border-color: #c8d7ef;
  }

  .nav a:hover {
    background: #edf2fa;
    border-color: #b7cae7;
  }

  .nav a.is-active,
  .nav a[aria-current="page"] {
    color: #fff;
    background: linear-gradient(180deg, #6a4792 0%, #4B2E6D 100%);
    border-color: #4B2E6D;
  }

  .nav a,
  .nav .btn {
    min-height: 36px;
    font-size: 12px;
    padding: 8px 11px;
  }

  .main {
    padding: 16px 0 98px;
  }

  body.has-sticky-actions .main {
    padding-bottom: 170px;
  }

  .sticky-action-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 65;
    padding: 8px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #c8d6ea;
    box-shadow: 0 10px 24px rgba(22, 33, 57, 0.2);
  }

  .sticky-action-bar .btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
  }

  .card:hover {
    transform: none;
  }

  .attendance-options {
    grid-template-columns: 1fr;
  }

  .attendance-option {
    min-height: 52px;
    justify-content: flex-start;
    text-align: left;
  }

  .attendance-card-head {
    flex-direction: column;
  }

  .attendance-select {
    min-height: 56px;
    font-size: 16px;
  }

  .attendance-card {
    padding: 12px;
  }

  .attendance-name {
    font-size: 15px;
  }

  .attendance-actions .btn {
    width: 100%;
  }

  h1::after {
    width: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .header,
  .pwa-update-banner,
  .pwa-install-banner { display: none !important; }
  .main { padding-top: 0 !important; }
  .flash { display: none !important; }
}

.print-builder {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid rgba(75, 46, 109, 0.25);
    border-radius: 12px;
    background: #fff;
}

.builder-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.builder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #d8dbe5;
    background: #f8f9fc;
    cursor: grab;
    user-select: none;
}

.builder-item.is-dragging {
    opacity: 0.6;
    cursor: grabbing;
}

.builder-handle {
    font-weight: 700;
    color: #4b2e6d;
    letter-spacing: 1px;
}
