*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --secondary-bg: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --surface: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--secondary-bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar {
  width: 240px;
  background: #0f172a;
  color: #fff;
  padding: 0.9rem;
  transition: width 0.2s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
}

.sidebar-toggle {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.side-btn {
  width: 100%;
  justify-content: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.side-icon {
  font-size: 1rem;
  line-height: 1;
}

.side-label {
  white-space: nowrap;
}

body.sidebar-collapsed .sidebar {
  width: 72px;
}

body.sidebar-collapsed .sidebar-title,
body.sidebar-collapsed .side-label {
  display: none;
}

body.sidebar-collapsed .side-btn {
  justify-content: center;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
}

body.sidebar-collapsed #sidebarToggle {
  transform: rotate(180deg);
}

/* Header */
header {
  background: var(--primary);
  color: #fff;
  padding: 1.2rem 2rem;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.7rem;
  font-weight: 700;
}

header .subtitle {
  font-size: 0.95rem;
  opacity: 0.85;
  margin-top: 0.2rem;
}

/* Main */
main {
  flex: 1;
  padding: 1.5rem 1rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

body.calendar-month-view main {
  max-width: none;
  padding: 0.85rem 0.35rem 1rem;
}

/* Week navigation */
.week-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.usage-mode-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.usage-mode-state {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.usage-mode-state.is-edit {
  color: #15803d;
}

.usage-mode-state.is-view {
  color: #b45309;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.2s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.switch input:checked + .slider {
  background-color: #2563eb;
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

.week-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  color: var(--primary);
  transition: background 0.15s;
}

.week-nav button:hover {
  background: var(--secondary-bg);
}

.period-label {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.55rem;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 600;
}

#weekLabel {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

/* Schedule table */
.schedule-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.schedule {
  border-collapse: collapse;
  min-width: 600px;
  width: 100%;
}

body.calendar-month-view .schedule {
  width: max-content;
  min-width: 100%;
  font-size: 0.76rem;
}

body.calendar-month-view .schedule th,
body.calendar-month-view .schedule td {
  white-space: nowrap;
  padding: 0.24rem 0.3rem;
}

body.calendar-month-view .schedule thead th.col-day {
  min-width: 0;
  width: 1%;
  padding-left: 3px;
  padding-right: 3px;
}

body.calendar-month-view .schedule tbody td.schedule-cell {
  min-width: 34px;
}

body.calendar-month-view .schedule thead th.col-post,
body.calendar-month-view .schedule tbody td.col-post,
body.calendar-month-view .schedule thead th.col-employee,
body.calendar-month-view .schedule tbody td.col-employee {
  width: 1%;
  min-width: 0;
  max-width: none;
  white-space: nowrap;
  padding-left: 3px;
  padding-right: 3px;
}

body.calendar-month-view .schedule tbody td.col-post {
  position: relative;
  padding: 0;
  vertical-align: middle;
  overflow: hidden;
  isolation: isolate;
}

body.calendar-month-view .schedule tbody td.col-post .post-diagonal-text {
  position: absolute;
  left: 3px;
  top: 50%;
  display: block;
  max-width: 48px;
  white-space: nowrap;
  line-height: 1;
  font-size: 0.74rem;
  transform: translateY(-50%) rotate(-30deg);
  transform-origin: left center;
}

.schedule th,
.schedule td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.6rem;
  text-align: center;
  font-size: 0.88rem;
}

.schedule thead th {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.schedule thead tr + tr th {
  border-top: 1px solid rgba(255, 255, 255, 0.35);
}

.schedule thead th.col-employee {
  background: #1e3a6e;
  text-align: left;
}

.schedule thead th.col-post {
  background: #1e3a6e;
  text-align: left;
}

.schedule thead th.col-post,
.schedule tbody td.col-post,
.schedule thead th.col-employee,
.schedule tbody td.col-employee {
  width: 1%;
  min-width: 0;
  white-space: nowrap;
  padding-left: 3px;
  padding-right: 3px;
}

.schedule thead th.col-day {
  min-width: 0;
  width: 1%;
  padding-left: 3px;
  padding-right: 3px;
}

.schedule thead th.col-day-month {
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  font-weight: 700;
}

.schedule thead th.col-day-name {
  font-size: 0.82rem;
  font-weight: 600;
}

.schedule thead th.col-day-number {
  font-size: 0.92rem;
  font-weight: 700;
}

.schedule thead th.col-day.day-size-small {
  font-size: 0.72rem;
}

.schedule thead th.col-day-name.day-size-small {
  font-size: 0.72rem;
}

.schedule thead th.col-day-number.day-size-small {
  font-size: 0.82rem;
}

.schedule thead th.col-day-month.day-size-small {
  font-size: 0.62rem;
}

.schedule thead th.col-day.day-size-medium {
  font-size: 0.82rem;
}

.schedule thead th.col-day-name.day-size-medium {
  font-size: 0.82rem;
}

.schedule thead th.col-day-number.day-size-medium {
  font-size: 0.92rem;
}

.schedule thead th.col-day-month.day-size-medium {
  font-size: 0.7rem;
}

.schedule thead th.col-day.day-size-large {
  font-size: 0.92rem;
}

.schedule thead th.col-day-name.day-size-large {
  font-size: 0.92rem;
}

.schedule thead th.col-day-number.day-size-large {
  font-size: 1.03rem;
}

.schedule thead th.col-day-month.day-size-large {
  font-size: 0.8rem;
}

.schedule thead th.col-day.holiday-col {
  color: #000;
}

.schedule tbody tr:nth-child(odd) {
  background: #f8fafc;
}

.schedule tbody td.col-employee {
  text-align: left;
  font-weight: 500;
  background: #f0f4ff;
}

.schedule tbody td.col-post {
  text-align: left;
  font-weight: 600;
  background: #e8eefc;
  color: #1f3a8a;
  vertical-align: top;
}

.schedule thead th.col-remarks {
  background: #1e3a6e;
  white-space: nowrap;
  min-width: 90px;
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
}

.schedule tbody td.col-remarks {
  white-space: nowrap;
  text-align: center;
  background: #f0f4ff;
  padding: 3px 4px;
  vertical-align: middle;
}

.repo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  margin: 1px 2px;
  letter-spacing: 0.01em;
}

.repo-badge--total {
  background: #1e3a6e;
  color: #fff;
}

.repo-badge--month {
  background: #dbeafe;
  color: #1e3a8a;
  border: 1px solid #93c5fd;
}

.schedule tbody tr.post-group-start td {
  border-top: 2px solid #bfdbfe;
}

.schedule tbody tr.post-group-end td {
  border-bottom: 3px solid #93c5fd;
}

.schedule tbody tr.post-group-start td.col-post {
  border-bottom: 3px solid #93c5fd;
}

.schedule tbody tr.post-divider-row td {
  text-align: left;
  font-weight: 700;
  color: #1e3a6e;
  background: #dbeafe;
  border-top: 2px solid #93c5fd;
}

.schedule tbody td.schedule-cell {
  cursor: pointer;
  transition:
    background 0.12s ease,
    box-shadow 0.12s ease;
}

.schedule tbody td.schedule-cell:hover {
  background: #eef4ff;
}

.schedule tbody td.schedule-cell.holiday-cell {
  background: #f3f4f6;
  color: #111827;
}

.schedule tbody td.schedule-cell.selected-cell {
  background: #dbeafe;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.schedule tbody td.schedule-cell.invalid-cell {
  background: #fee2e2;
  box-shadow: inset 0 0 0 1px #ef4444;
}

.schedule tbody td.empty-cell {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Shift chip */
.shift-chip {
  display: inline-block;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.82rem;
  cursor: pointer;
  border: 1px solid #93c5fd;
  transition: background 0.15s;
  white-space: nowrap;
}

.shift-chip:hover {
  background: #bfdbfe;
}

.leave-chip {
  display: inline-block;
  color: #334155;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.8rem;
  border: 1px solid rgba(51, 65, 85, 0.25);
  white-space: nowrap;
  margin-right: 3px;
}

.leave-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  margin: 0 auto 0.65rem;
  max-width: 980px;
}

.leave-legend-title {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-right: 0.25rem;
}

.leave-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text);
}

.leave-legend-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
}

.leave-legend-btn:hover {
  background: #f8fafc;
}

.leave-legend-btn.active {
  border-color: #2563eb;
  box-shadow: inset 0 0 0 1px #2563eb;
  background: #eff6ff;
}

.leave-legend-clear {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  line-height: 1;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
}

.leave-legend-clear:hover {
  background: #fee2e2;
}

.legend-stack {
  max-width: 980px;
  margin: 0 auto 0.7rem;
}

.legend-stack .leave-legend {
  margin-bottom: 0.4rem;
}

.legend-stack .leave-legend:last-child {
  margin-bottom: 0;
}

/* Controls */
.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quick-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1.25rem;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  margin: 0 0 0.55rem;
}

.quick-editor-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.quick-editor-row label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

#quickShiftInput {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
  width: 180px;
}

#editModeSelect,
#interactionModeSelect {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.4rem 0.55rem;
  min-width: 220px;
  background: var(--surface);
}

#quickShiftInput:focus {
  outline: none;
  border-color: var(--primary);
}

.quick-suggestions {
  margin-top: 0.55rem;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.quick-suggestion {
  border: 1px solid #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 0.18rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.quick-editor-settings {
  margin-top: 0.55rem;
  justify-content: space-between;
}

.quick-input-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quick-input-hint.ok {
  color: #15803d;
}

.quick-input-hint.error {
  color: #b91c1c;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition:
    background 0.15s,
    opacity 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 200;
  width: 100%;
  max-width: 400px;
  padding: 1.75rem 1.5rem 1.25rem;
}

.modal-wide {
  max-width: 900px;
}

.modal h2 {
  margin-bottom: 1.1rem;
  font-size: 1.2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.85rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

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

.form-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

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

.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

.tools-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.tool-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  margin-bottom: 0.8rem;
}

.tool-panel h3 {
  margin-bottom: 0.7rem;
  font-size: 1rem;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.7rem;
}

.inline-form input,
.inline-form select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.38rem 0.55rem;
  font-size: 0.92rem;
  background: var(--surface);
  color: var(--text);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.list-box,
.report-box {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  padding: 0.65rem;
  font-size: 0.86rem;
  max-height: 220px;
  overflow: auto;
}

.report-box {
  white-space: pre-wrap;
}

.info-box {
  border: 1px solid #93c5fd;
  border-radius: 6px;
  background: #dbeafe;
  padding: 1rem;
  font-size: 0.9rem;
  margin-top: 1rem;
}

.info-box p {
  margin-bottom: 0.5rem;
}

.info-box p:last-child {
  margin-bottom: 0;
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
}

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

.hidden {
  display: none !important;
}

/* Footer */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Mobile Drawer Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* Responsive */
@media (max-width: 768px) {
  /* Mobile: sidebar becomes absolute overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  /* Show sidebar on mobile when not collapsed */
  body:not(.sidebar-collapsed) .sidebar {
    transform: translateX(0);
  }

  /* Show backdrop when sidebar is open on mobile */
  body:not(.sidebar-collapsed) .sidebar-backdrop {
    display: block;
  }

  /* On mobile, collapsed = hidden (no mini-bar) */
  body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

  /* Hide collapse arrow on mobile - tap backdrop to close */
  #sidebarToggle {
    transform: none !important;
  }

  header {
    padding: 1rem;
  }
  header h1 {
    font-size: 1.3rem;
  }
  .modal {
    max-width: calc(100% - 2rem);
  }
}

/* ── Login screen ─────────────────────────────────────────────────────────── */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  z-index: 10000;
}

.login-card {
  background: #1e293b;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: #60a5fa;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 0.25rem;
}

.login-title {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: #94a3b8;
  margin: 0 0 1.75rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.login-field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-field input {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f1f5f9;
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}

.login-field input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.login-btn {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 700;
}

.login-error {
  background: #450a0a;
  border: 1px solid #dc2626;
  border-radius: 6px;
  color: #fca5a5;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

