:root {
  --bg: #ffffff;
  --card: rgba(255, 255, 255, 0.7);
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #00A651;
  --border: rgba(15, 23, 42, 0.08);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.glass {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Header */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.site-header h1 {
  margin: 0;
  font-size: 20px;
}

.site-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
}

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

.brand-logo {
  width: clamp(30px, 6vw, 44px);
  height: auto;
  max-height: clamp(30px, 6vw, 44px);
  border-radius: clamp(8px, 1.6vw, 12px);
  flex: 0 0 auto;
  object-fit: contain;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.auth {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
}

.auth a {
  color: var(--accent);
  text-decoration: none;
}

.auth a:hover {
  text-decoration: underline;
}

.mobile-menu-auth {
  display: none;
  position: relative;
}

.mobile-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.mobile-menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  z-index: 30;
}

.mobile-menu-auth.open .mobile-menu-panel {
  display: grid;
  gap: 8px;
}

.mobile-menu-user {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  padding: 4px 2px;
}

.mobile-menu-panel a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  font-weight: 600;
}

.mobile-menu-panel a:hover {
  border-color: rgba(0, 166, 81, 0.35);
}

.mobile-logout-form {
  margin: 0;
}

.mobile-logout-form .logout-button {
  width: 100%;
}

.main-nav {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.nav-link:hover {
  border-color: rgba(0, 166, 81, 0.35);
}

.nav-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Messages */
.messages {
  margin: 12px 0;
  display: grid;
  gap: 8px;
}

.message {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 166, 81, 0.08);
  border: 1px solid var(--border);
}

.message.error {
  background: #fee2e2;
  color: #991b1b;
}

.message.success {
  background: #dcfce7;
  color: #166534;
}

.message.warning {
  background: #fef3c7;
  color: #92400e;
}

/* Table */
.table {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr 1.2fr 1.2fr 0.8fr 2fr;
  background: var(--card);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  gap: 8px;
  align-items: center;
}

.table-row.edit-mode {
  grid-template-columns: 1fr 1fr 1.2fr 1.2fr 1.2fr 0.8fr 1.2fr 0.5fr;
  align-items: start;
}

.table-row.edit-mode.edit-mode-with-date {
  grid-template-columns: 1fr 1fr 1fr 1.2fr 1.2fr 1.2fr 0.8fr 1.2fr 0.5fr;
}

.table-header {
  font-weight: 600;
  background: rgba(0, 166, 81, 0.08);
}

/* Edit Mode */
.edit-mode input,
.edit-mode select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  font-size: 14px;
}

.edit-mode input[type="checkbox"] {
  width: auto;
  height: 18px;
  cursor: pointer;
}

.edit-mode input[type="hidden"] {
  display: none;
}

.edit-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.edit-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* Date Filter */
.date-filter {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.date-filter label {
  font-weight: 600;
}

.date-filter input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

/* Buttons */
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

.logout-form {
  margin: 0;
}

.logout-button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.save-button {
  margin-top: 16px;
  width: 100%;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.add-row-button {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.day-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff !important;
  text-decoration: none;
  font-weight: 700;
}

.day-switch:hover {
  filter: brightness(0.95);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-row {
  margin-bottom: 10px;
}

.filter-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  padding: 6px 10px;
}

.filter-toggle {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  list-style: none;
}

.filter-toggle::-webkit-details-marker {
  display: none;
}

.filter-panel[open] .filter-toggle {
  margin-bottom: 8px;
}

.class-filter {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-direction: column;
}

.class-filter-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.class-chip-list {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: min(58vw, 720px);
  white-space: nowrap;
  padding-bottom: 2px;
}

.class-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.class-chip:hover {
  border-color: rgba(0, 166, 81, 0.35);
}

.class-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filter-submit {
  height: 32px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
}

.filter-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.filter-reset:hover {
  border-color: rgba(0, 166, 81, 0.35);
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.view-toggle:hover {
  filter: brightness(0.95);
}

.scope-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.95);
}

.scope-btn {
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 6px 12px;
  font-weight: 600;
}

.scope-btn:last-child {
  border-right: 0;
}

.scope-btn.active {
  background: var(--accent);
  color: #fff;
}

.scope-btn:hover {
  filter: none;
}

.month-table-row,
.month-table-header {
  grid-template-columns: 1fr 1fr 1.2fr 1.2fr 1.2fr 0.8fr 1.4fr;
}

.month-day-title {
  margin: 20px 0 8px;
  color: var(--text);
}

.day-picker-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.day-picker-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.day-picker-toggle {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
}

.day-picker-toggle:hover {
  color: var(--accent);
}

/* Upload */
.upload-layout {
  display: grid;
  gap: 14px;
}

.upload-card {
  border-radius: 16px;
  padding: 16px;
}

.upload-help {
  margin: 6px 0 14px;
}

.upload-form p {
  margin: 0 0 10px;
}

.upload-form input[type="file"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.95);
}

.upload-form-actions {
  display: flex;
  justify-content: flex-end;
}

.upload-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-log-head h3 {
  margin: 0;
}

.upload-log-list {
  display: grid;
  gap: 10px;
}

.upload-log-card {
  border-radius: 14px;
  padding: 12px;
}

.upload-log-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.upload-log-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.upload-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border);
}

.upload-status-badge.status-ok {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.upload-status-badge.status-partial {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}

.upload-status-badge.status-error {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

.upload-log-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0;
  font-size: 13px;
}

.upload-log-details {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.8);
}

.upload-log-details summary {
  cursor: pointer;
  font-weight: 600;
}

.upload-error-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.upload-error-list li {
  margin: 4px 0;
}

.upload-error-list li span {
  display: block;
  color: var(--text);
}

.upload-log-pre {
  white-space: pre-wrap;
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.35;
}

.upload-log-delete-form,
.upload-log-delete-all-form {
  margin: 10px 0 0;
}

.upload-log-delete-btn,
.upload-log-delete-all {
  background: #b91c1c;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
}

.upload-log-delete-btn:hover,
.upload-log-delete-all:hover {
  filter: brightness(0.95);
}

/* Login */
.login-wrap {
  min-height: calc(100vh - 220px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.login-card {
  width: 100%;
  max-width: 460px;
  border-radius: 20px;
  padding: 28px;
}

.login-title {
  margin: 0;
  font-size: 1.7rem;
}

.login-subtitle {
  margin: 8px 0 20px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-field {
  display: grid;
  gap: 6px;
}

.login-field label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.login-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  padding: 11px 12px;
  font-size: 0.98rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-field input:focus {
  border-color: rgba(0, 166, 81, 0.55);
  box-shadow: 0 0 0 3px rgba(0, 166, 81, 0.15);
}

.login-error-box {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.login-field-error {
  color: #b91c1c;
  font-size: 0.85rem;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
  border-radius: 10px;
  padding: 11px 14px;
}

/* Responsive */
@media (max-width: 900px) {
  .header-row {
    align-items: flex-start;
  }

  .auth {
    display: none;
  }

  .mobile-menu-auth {
    display: block;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .day-picker-form {
    width: 100%;
    justify-content: space-between;
  }

  .day-picker-toggle {
    flex: 1;
    text-align: center;
    font-size: 1.2rem;
    line-height: 1.25;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
  }

  .class-filter {
    width: 100%;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .class-chip-list {
    flex: 1;
    min-width: 0;
    max-width: 100%;
  }

  .scope-switch {
    flex: 1;
    min-width: 0;
  }

  .scope-btn {
    flex: 1;
    padding: 8px 10px;
  }

  .table-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px;
    align-items: start;
  }

  .table {
    gap: 10px;
  }

  .table-row:not(.table-header):not(.edit-mode) {
    grid-template-columns: 1fr;
    gap: 8px;
    border-radius: 14px;
    padding: 12px;
  }

  .table-row:not(.table-header):not(.edit-mode) > div {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px dashed rgba(15, 23, 42, 0.08);
    padding-bottom: 6px;
    font-size: 0.95rem;
    line-height: 1.3;
    word-break: break-word;
  }

  .table-row:not(.table-header):not(.edit-mode) > div::before {
    content: attr(data-label);
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    min-width: 86px;
    flex: 0 0 86px;
  }

  .table-row:not(.table-header):not(.edit-mode) > div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .table-row.edit-mode {
    grid-template-columns: 1fr 1fr;
  }

  .table-row.edit-mode.edit-mode-with-date {
    grid-template-columns: 1fr 1fr;
  }

  .month-table-row,
  .month-table-header {
    grid-template-columns: 1fr 1fr;
  }

  .table-header {
    display: none;
  }

  .upload-log-card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .upload-status-badge {
    min-width: auto;
  }

  .login-wrap {
    min-height: auto;
    padding: 10px 0;
  }

  .login-card {
    max-width: 100%;
    padding: 20px;
    border-radius: 14px;
  }
}

@media (max-width: 768px) {
  .top-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .class-filter {
    display: grid;
    gap: 4px;
  }

  .class-chip-list {
    max-width: 100%;
  }

  .view-toggle {
    width: 100%;
  }

  .scope-switch {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .table-row {
    grid-template-columns: 1fr;
  }

  .table-row.edit-mode,
  .table-row.edit-mode.edit-mode-with-date,
  .month-table-row,
  .month-table-header {
    grid-template-columns: 1fr;
  }

  .day-picker-toggle {
    font-size: 1.05rem;
  }

  .view-toggle {
    height: 34px;
    padding: 0 10px;
  }
}
