:root {
  --bg: #f7f3ed;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #7c3aed;
  --primary-dark: #5b21b6;
  --danger: #b91c1c;
  --soft: #f5f3ff;
  --warning: #fff7ed;
  --success: #ecfdf5;
  --error: #fef2f2;
  --shadow: 0 14px 35px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

a:hover {
  text-decoration: underline;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 800;
  color: var(--text);
  font-size: 1.05rem;
}

.user-pill {
  margin-left: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  font-size: 0.85rem;
}

.top-nav,
.toolbar-actions,
.export-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.top-nav a,
.link-button {
  font-size: 0.95rem;
  color: var(--text);
}

.inline-form {
  display: inline;
  margin: 0;
}

.link-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.page {
  padding: 1rem;
}

.panel,
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 1rem;
  margin-bottom: 1rem;
}

.compact-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.auth-card {
  width: min(440px, 100%);
  margin: 8vh auto;
  padding: 1.4rem;
}

h1,
h2 {
  margin: 0 0 0.35rem;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.stack-form {
  display: grid;
  gap: 0.9rem;
}

.stack-form label,
.user-form label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  line-height: 1;
}

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

.primary-button:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.secondary-button {
  background: var(--soft);
  color: var(--primary-dark);
}

.secondary-button:hover {
  text-decoration: none;
}

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

.flash {
  max-width: 1100px;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.flash-success {
  background: var(--success);
}

.flash-error {
  background: var(--error);
}

.flash-warning {
  background: var(--warning);
}

.schedule-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
}

.schedule-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: #fff;
}

.schedule-table th,
.schedule-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.schedule-table th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  padding: 0.75rem;
  text-align: left;
  font-size: 0.9rem;
}

.schedule-table td {
  height: 58px;
  padding: 0.4rem;
}

.time-col {
  width: 90px;
  background: #fbfbfb;
  font-weight: 700;
  color: var(--muted);
}

.schedule-table th.time-col {
  z-index: 12;
}

.date-row td {
  position: sticky;
  left: 0;
  z-index: 8;
  height: auto;
  padding: 0.55rem 0.75rem;
  background: #111827;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.slot-cell {
  position: relative;
}

.event-card {
  display: grid;
  gap: 0.15rem;
  width: 100%;
  margin-bottom: 0.35rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid #ddd6fe;
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  background: #faf5ff;
  color: var(--text);
  text-align: left;
}

button.event-card {
  cursor: default;
}

button.event-card.is-editable {
  cursor: pointer;
}

.event-card span,
.event-card em,
.event-card small {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: normal;
}

.add-slot-button {
  width: 100%;
  min-height: 28px;
  border: 1px dashed #c4b5fd;
  border-radius: 10px;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  opacity: 0.55;
}

.add-slot-button:hover {
  opacity: 1;
  background: var(--soft);
}

.event-dialog {
  width: min(680px, calc(100% - 2rem));
  border: 0;
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}

.event-dialog::backdrop {
  background: rgba(17, 24, 39, 0.55);
}

.dialog-header,
.dialog-actions,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-header {
  margin-bottom: 0.35rem;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 1.3rem;
}

.form-grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.checkbox-label {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem !important;
  font-weight: 500 !important;
}

.checkbox-label input {
  width: auto;
}

.delete-form {
  display: none;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.user-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin: 1rem 0;
}

.simple-table {
  width: 100%;
  border-collapse: collapse;
}

.simple-table th,
.simple-table td {
  padding: 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.print-body {
  background: #fff;
  padding: 1rem;
}

.print-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}


.print-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.print-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -0.4rem 0 0.85rem;
}

.print-empty {
  margin-top: 1rem;
}

.print-table {
  min-width: 0;
  font-size: 10px;
}

.print-table th {
  position: static;
}

.print-table td {
  height: auto;
  min-height: 35px;
  padding: 0.25rem;
}

.print-event-card {
  break-inside: avoid;
  box-shadow: none;
}

@media (max-width: 820px) {
  .app-header,
  .compact-panel,
  .print-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-form,
  .form-grid-two {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .schedule-table {
    width: 100%;
    table-layout: fixed;
  }

  .schedule-table th,
  .schedule-table td {
    border-color: #999;
  }

  .date-row td {
    background: #ddd !important;
    color: #000 !important;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.language-switch a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-decoration: none;
}

.language-switch a.is-active {
  background: var(--soft);
  color: var(--primary-dark);
}

.auth-link {
  margin-top: 1rem;
  text-align: center;
}

.wide-card {
  max-width: 720px;
}

.soft-divider {
  border: 0;
  border-top: 1px solid #eadfd7;
  margin: 1rem 0;
}

.mini-info {
  background: #fff7f0;
  border: 1px solid #eadfd7;
  border-radius: 12px;
  padding: .85rem 1rem;
  margin: 1rem 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.sub-panel {
  background: #fff;
  border: 1px solid #eadfd7;
  border-radius: 16px;
  padding: 1rem;
  margin: 1rem 0;
}

.sub-panel h2 {
  margin-top: 0;
}

.attention-panel {
  border-color: #d4a373;
  background: #fffaf4;
}

.copy-box {
  background: #f7fff7;
  border: 1px solid #b9deb9;
  border-radius: 16px;
  padding: 1rem;
  margin: 1rem 0;
}

.copy-box input {
  width: 100%;
  margin-top: .5rem;
  padding: .75rem;
  border: 1px solid #cfc4bd;
  border-radius: 10px;
  font: inherit;
}

.action-cell {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

/* Continuous multi-slot events: show one clean block instead of repeated cards. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.slot-content {
  min-height: 32px;
}

.slot-content.has-events {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.1rem;
  align-items: stretch;
  gap: 0.35rem;
}

.slot-content.is-empty {
  display: block;
}

.slot-events {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.slot-content.has-events .add-slot-button {
  width: 2.1rem;
  height: 100%;
  min-height: 100%;
  align-self: stretch;
  padding: 0;
}

.slot-content.is-empty .add-slot-button {
  width: 100%;
}

.event-segment {
  min-height: 34px;
  margin-bottom: 0;
  box-sizing: border-box;
}

.event-segment-single {
  margin-bottom: 0;
}

.event-segment-start {
  border-bottom-color: transparent;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: -0.45rem;
  padding-bottom: 0.7rem;
}

.event-segment-middle {
  border-top-color: transparent;
  border-bottom-color: transparent;
  border-radius: 0;
  margin-top: -0.45rem;
  margin-bottom: -0.45rem;
  min-height: calc(100% + 0.9rem);
}

.event-segment-end {
  border-top-color: transparent;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  margin-top: -0.45rem;
  padding-top: 0.7rem;
}

.event-segment.is-continuation {
  cursor: pointer;
}

button.event-segment.is-continuation[disabled] {
  cursor: default;
}

.print-slot-events {
  gap: 0;
}

.print-table .event-segment-start {
  margin-bottom: -0.3rem;
  padding-bottom: 0.5rem;
}

.print-table .event-segment-middle {
  margin-top: -0.3rem;
  margin-bottom: -0.3rem;
  min-height: calc(100% + 0.6rem);
}

.print-table .event-segment-end {
  margin-top: -0.3rem;
  padding-top: 0.5rem;
}
