:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --border: #bdc3c7;
  --bg-alt: #f8f9fa;
  --text: #2c3e50;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Sarabun", "Tahoma", sans-serif;
  color: var(--text);
  background: #ecf0f1;
  line-height: 1.5;
}

a {
  color: var(--primary-light);
}

/* Public calendar */
.calendar-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.calendar-header {
  text-align: center;
  margin-bottom: 1.25rem;
  padding: 1.25rem 1rem;
  background: linear-gradient(135deg, #1a5276 0%, #2980b9 100%);
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.calendar-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.65rem;
  font-weight: 700;
}

.calendar-header .subtitle {
  margin: 0;
  font-size: 1.1rem;
  opacity: 0.95;
}

.toolbar-block {
  margin-bottom: 1rem;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.toolbar-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.toolbar-top .btn-primary,
.toolbar-top .btn-outline {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  font-size: 0.9rem;
  text-decoration: none;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.toolbar.toolbar--filters {
  margin-bottom: 0;
  border: none;
  border-radius: 0;
}

.toolbar-filters {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.65rem 1rem;
  flex: 1;
  min-width: 0;
}

.toolbar-field {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.toolbar-field--search {
  flex: 1;
  min-width: 10rem;
}

.toolbar-field--search input[type="search"] {
  width: 100%;
  min-width: 8rem;
}

.toolbar label {
  font-size: 0.9rem;
  margin-right: 0;
  white-space: nowrap;
}

.toolbar select,
.toolbar input {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}

.toolbar .actions a,
.toolbar .actions button {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  font-size: 0.9rem;
  text-decoration: none;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff !important;
}

.btn-outline {
  background: #fff;
  color: var(--primary) !important;
  border: 1px solid var(--primary) !important;
}

/* Table like PDF */
.calendar-table-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

table.calendar-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

table.calendar-table th {
  background: #2c3e50;
  color: #fff;
  padding: 0.65rem 0.75rem;
  text-align: center;
  font-weight: 600;
  border: 1px solid #1a252f;
}

table.calendar-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

table.calendar-table tr:nth-child(even) {
  background: var(--bg-alt);
}

table.calendar-table tr:hover {
  background: #eaf2f8;
}

table.calendar-table tr.row-exam-term td,
table.calendar-table tr.row-exam-term:nth-child(even) td {
  background: #fff3cd;
}

table.calendar-table tr.row-exam-term:hover td {
  background: #ffeaa7;
}

.events-table tr.row-exam-term td {
  background: #fff3cd;
}

.col-week {
  width: 72px;
  text-align: center;
  font-weight: 600;
}

.col-date {
  width: 140px;
  white-space: nowrap;
}

.col-responsible {
  width: 220px;
}

table.calendar-table td.col-responsible {
  padding: 0.3rem 0.5rem;
  vertical-align: middle;
}

table.calendar-table td.col-responsible .dept-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 0.82rem;
  color: #fff;
  text-align: center;
  white-space: normal;
  line-height: 1.3;
}

.dept-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-size: 0.82rem;
  color: #fff;
  white-space: nowrap;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 2px;
}

.site-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: #7f8c8d;
}

/* Admin */
.admin-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-nav {
  background: #2c3e50;
  color: #fff;
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.admin-nav a {
  color: #ecf0f1;
  text-decoration: none;
  margin-left: 1rem;
}

.admin-nav a:hover {
  text-decoration: underline;
}

.admin-content {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
}

.admin-content.admin-content--wide {
  max-width: min(100%, 1320px);
}

.card {
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card.card-table {
  padding: 0;
  overflow: hidden;
}

.card-table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.card-table-meta {
  font-size: 0.9rem;
  color: #7f8c8d;
}

.card-table .data-table {
  margin: 0;
}

.data-table tr.row-current td {
  background: #f4fbf6;
}

.card-table-calendars {
  overflow-x: auto;
}

.calendars-table {
  min-width: 1080px;
  table-layout: fixed;
}

.calendars-table .col-order {
  width: 4.5rem;
  text-align: center;
  color: #7f8c8d;
}

.calendars-table .col-name {
  width: auto;
  min-width: 14rem;
}

a.calendar-name-link {
  color: var(--primary-light);
  font-weight: 600;
  text-decoration: none;
}

a.calendar-name-link:hover {
  text-decoration: underline;
}

.calendars-table .col-semester {
  width: 7rem;
  white-space: nowrap;
}

.calendars-table .col-year {
  width: 6.5rem;
  text-align: center;
  white-space: nowrap;
}

.calendars-table .col-events {
  width: 6rem;
  text-align: center;
  white-space: nowrap;
}

.calendars-table .col-week1 {
  width: 14rem;
  min-width: 14rem;
  white-space: nowrap;
}

.calendars-table .col-status {
  width: 9.5rem;
}

.calendars-table .col-actions {
  width: 11.5rem;
}

.card-table-events {
  overflow-x: auto;
}

.events-table {
  min-width: 1080px;
  table-layout: fixed;
}

.events-table .col-week {
  width: 5rem;
  text-align: center;
  white-space: nowrap;
}

.events-table .col-date {
  width: 11rem;
  white-space: nowrap;
}

.events-table .col-title {
  width: auto;
  min-width: 16rem;
}

.events-table .col-dept {
  width: 12rem;
}

.events-table .col-status {
  width: 5.5rem;
  white-space: nowrap;
}

.events-table .col-actions {
  width: 8rem;
  white-space: nowrap;
}

/* Modal */
body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  color: #7f8c8d;
  padding: 0 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.25rem;
}

.modal-body .form-group {
  margin-bottom: 0.85rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.modal-checkbox {
  padding-top: 1.5rem;
}

.modal-dept-note {
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.req {
  color: #c0392b;
}

.hint {
  display: block;
  color: #7f8c8d;
  font-size: 0.82rem;
  margin-top: 0.25rem;
}

a.btn-edit-event {
  cursor: pointer;
}

.calendar-options label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: normal;
}

.calendar-actions form.inline-form {
  display: inline;
}

.action-icons {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex-wrap: wrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--primary-light);
  cursor: pointer;
  text-decoration: none;
  line-height: 0;
  vertical-align: middle;
}

.icon-btn:hover {
  background: #ecf0f1;
  text-decoration: none;
}

.icon-btn-danger {
  color: #c0392b;
}

.icon-btn-danger:hover {
  background: #fdecea;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary-light);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.btn-link-danger {
  color: #c0392b;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  margin-right: 0.25rem;
}

.badge-current {
  background: #d5f5e3;
  color: #1e8449;
}

.badge-public {
  background: #d6eaf8;
  color: #1a5276;
}

#modal_week_number.week-auto-filled {
  background: #eafaf1;
  border-color: #27ae60;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-success {
  background: #27ae60;
  color: #fff;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
}

.btn-secondary {
  background: #95a5a6;
  color: #fff;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.alert-success {
  background: #d5f5e3;
  color: #1e8449;
}

.alert-error {
  background: #fadbd8;
  color: #922b21;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  background: var(--bg-alt);
}

.login-box {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.login-box h1 {
  text-align: center;
  font-size: 1.35rem;
  margin-top: 0;
}

@media (max-width: 960px) {
  .toolbar-filters {
    flex-wrap: wrap;
  }
}

@media print {
  body {
    background: #fff;
  }

  .toolbar-block,
  .toolbar,
  .legend,
  .site-footer,
  .no-print {
    display: none !important;
  }

  .calendar-header {
    background: none !important;
    color: #000 !important;
    box-shadow: none;
  }

  .calendar-table-wrap {
    border: none;
    box-shadow: none;
  }
}
