:root {
  /* Light theme colors */
  --bg-primary: #f4f7fa;
  --bg-secondary: #fff;
  --bg-modal: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
  --bg-station-header: rgba(0, 122, 204, 0.05);
  --bg-row: #f7f9fc;
  --bg-add-row: rgba(221, 233, 255, 0.4);
  --bg-scrollable: #ffffff;

  --text-primary: #0f3460;
  --text-secondary: #4a6278;
  --text-label: #4f6a86;

  --border-primary: #007acc;
  --border-secondary: #dbe5f3;
  --border-input: #bcd0eb;
  --border-add-row: #9db8dd;
  --border-station: #d4e2f0;

  --shadow-card: 0 2px 5px rgba(0,0,0,0.1);
  --shadow-modal: 0 18px 40px rgba(15, 40, 75, 0.25);
  --shadow-form: 0 14px 32px rgba(15, 40, 75, 0.18);

  --modal-backdrop: rgba(0,0,0,0.5);
  --login-backdrop: rgba(0,0,0,0.7);
}

html.dark-theme {
  /* Dark theme colors */
  --bg-primary: #1a1d23;
  --bg-secondary: #242831;
  --bg-modal: linear-gradient(180deg, #2a2f3a 0%, #242831 100%);
  --bg-station-header: rgba(0, 122, 204, 0.15);
  --bg-row: #2a2f3a;
  --bg-add-row: rgba(0, 122, 204, 0.1);
  --bg-scrollable: #242831;

  --text-primary: #e1e8f0;
  --text-secondary: #b8c5d6;
  --text-label: #94a3b8;

  --border-primary: #3a8dd6;
  --border-secondary: #3a4556;
  --border-input: #4a5568;
  --border-add-row: #4a7ab8;
  --border-station: #3a4556;

  --shadow-card: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-modal: 0 18px 40px rgba(0, 0, 0, 0.6);
  --shadow-form: 0 14px 32px rgba(0, 0, 0, 0.5);

  --modal-backdrop: rgba(0,0,0,0.7);
  --login-backdrop: rgba(0,0,0,0.85);
}

body {
  font-family: sans-serif;
  margin: 0;
  padding: 1rem;
  background: var(--bg-primary);
  color: var(--text-secondary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  position: relative;
}

h1 {
  margin: 0;
  text-align: center;
  color: var(--text-primary);
}

.page-header .admin-btn,
.page-header .login-btn {
  position: absolute;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  padding: 0 1rem;
}

.page-header .help-btn {
  position: absolute;
  right: 145px;
  padding: 0.25rem;
  background: transparent;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  transition: background 0.2s ease, border-color 0.2s ease;
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--text-primary);
}

.page-header .help-btn:hover {
  background: var(--bg-row);
  border-color: var(--border-primary);
  transform: none;
  box-shadow: none;
}

.page-header .theme-toggle-btn {
  position: absolute;
  right: 90px;
  padding: 0.25rem;
  background: transparent;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.page-header .theme-toggle-btn:hover {
  background: var(--bg-row);
  border-color: var(--border-primary);
  transform: none;
  box-shadow: none;
}

.theme-toggle-btn .theme-icon {
  width: calc(100% - 0.5rem);
  height: calc(100% - 0.5rem);
  filter: brightness(0) saturate(100%) invert(17%) sepia(25%) saturate(2394%) hue-rotate(186deg) brightness(95%) contrast(97%);
}

html.dark-theme .theme-toggle-btn .theme-icon {
  filter: brightness(0) saturate(100%) invert(93%) sepia(5%) saturate(577%) hue-rotate(183deg) brightness(99%) contrast(92%);
}

.theme-toggle-btn .sun-icon {
  display: none;
}

.theme-toggle-btn .moon-icon {
  display: block;
}

html.dark-theme .theme-toggle-btn .sun-icon {
  display: block;
}

html.dark-theme .theme-toggle-btn .moon-icon {
  display: none;
}

@media (max-width: 600px) {
  .page-header {
    justify-content: center;
    flex-wrap: wrap;
  }

  .page-header .help-btn,
  .page-header .theme-toggle-btn,
  .page-header .admin-btn,
  .page-header .login-btn {
    position: static;
    right: auto;
  }
}

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

.station {
  background: var(--bg-secondary);
  border: 2px solid var(--border-primary);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow-card);
}

.station-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -0.5rem -0.5rem 0.5rem -0.5rem;
  padding: 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--border-primary);
  cursor: grab;
  border-bottom: 1px solid var(--border-station);
  background: var(--bg-station-header);
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}

.station-header:active {
  cursor: grabbing;
}

.station-body {
  padding-top: 0.25rem;
}

.apparatus {
  padding: 0.5rem;
  margin: 0.25rem 0;
  border-radius: 4px;
  text-align: center;
  font-weight: bold;
  color: white;
  cursor: grab;
  background: #444;
  position: relative;
  overflow: hidden;
}

.ghost {
  opacity: 0.2;
  cursor: default;
}

.red { background: #d32f2f !important; }
.green { background: #388e3c !important; }
.blue { background: #1976d2 !important; }
.yellow { background: #fbc02d !important; color: #1f1f1f !important; }
.purple { background: #6a1b9a !important; }
.black { background: #212121 !important; }
.apparatus.reserve::after,
.selection-btn.reserve::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255,255,255,0.22) 0,
    rgba(255,255,255,0.22) 8px,
    transparent 8px,
    transparent 16px
  );
}

.apparatus.oos,
.selection-btn.oos {
  opacity: 0.75;
}

.apparatus.oos s,
.selection-btn.oos s {
  text-decoration-color: black;
}

.apparatus.ghost {
  opacity: 0.2;
  cursor: default;
}

.admin-btn {
  padding: 0.5rem 1rem;
}

.login-btn {
  padding: 0.5rem 1rem;
  background: #0f83ff;
}

#adminModal, #editModal, #helpModal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--modal-backdrop);
  z-index: 1000;
}

.modal-content {
  background: var(--bg-modal);
  width: min(92vw, 560px);
  margin: 5% auto;
  padding: 1.5rem;
  border-radius: 12px;
  position: relative;
  box-shadow: var(--shadow-modal);
  box-sizing: border-box;
  max-height: min(92vh, 760px);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.tabs {
  display: flex;
  margin-bottom: 1rem;
  border-bottom: 1px solid #ccc;
}

.tab {
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: none;
  background: none;
  font-weight: bold;
  color: var(--text-secondary);
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  border-bottom: 3px solid var(--border-primary);
  color: var(--border-primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-header {
  margin-bottom: 1rem;
}

.tab-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.tab-header p {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.row {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-secondary);
  background: var(--bg-row);
}

.row-body {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.row-body.column {
  flex-direction: column;
  gap: 0.5rem;
}

.row-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.row-actions button {
  min-width: 96px;
}

.data-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.data-note {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.import-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  border-radius: 6px;
  background: #1f2933;
  color: #fff;
  cursor: pointer;
}

.import-label:hover {
  box-shadow: 0 4px 12px rgba(31, 41, 51, 0.3);
}

.import-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.row input,
.row select {
  flex: 1 1 auto;
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 0.5 0.5 50px;
  min-width: 0;
}

.row-body.column .field {
  flex: 0 0 auto;
}

.edit-fields {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#editModal .edit-fields .field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.5rem;
  flex: none;
}

#editModal .edit-fields .field:last-child {
  margin-bottom: 0;
}

.checkbox-field {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.checkbox-field input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.checkbox-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: none;
  letter-spacing: normal;
}

.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scrollable {
  border: 1px solid var(--border-secondary);
  padding: 0.75rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  background: var(--bg-scrollable);
}

input, select, textarea {
  width: 100%;
  margin: 0;
  box-sizing: border-box;
  font-size: 1rem;
}

.row input,
.row select {
  box-sizing: border-box;
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  padding: 6px 10px !important;
  line-height: 22px !important;
}

.modal-content input[type="text"],
.modal-content input[type="number"],
.modal-content input[type="tel"],
.modal-content input[type="search"],
.modal-content select {
  border: 1px solid var(--border-input);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}

.modal-content select {
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%233c5780' stroke-width='1.3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  background-size: 10px 6px;
  padding-right: 1.6rem;
}

.modal-content textarea {
  padding: 0.45rem 0.55rem;
  min-height: 3.25rem;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  resize: vertical;
}


button {
  background: #0f83ff;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 131, 255, 0.3);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

button.danger {
  background: #f05252;
  box-shadow: none;
}

button.danger:hover {
  box-shadow: 0 4px 12px rgba(240, 82, 82, 0.28);
}

button.secondary {
  background: #1f2933;
}

button.secondary:hover {
  box-shadow: 0 4px 12px rgba(31, 41, 51, 0.3);
}

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

.modal-actions button {
  min-width: 120px;
}

.tab-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
  gap: 0.5rem;
}

.hidden {
  display: none !important;
}

.add-row {
  border-style: dashed;
  border-color: var(--border-add-row);
  background: var(--bg-add-row);
}

.add-row input,
.add-row select {
  background: var(--bg-secondary);
}

@media (max-width: 720px) {
  .modal-content {
    width: min(96vw, 560px);
    padding: 1.25rem;
  }

}

@media (max-width: 600px) {
  .modal-content {
    width: calc(100vw - 1.5rem);
    padding: 1rem;
    margin: 1.5rem auto;
  }

  .row {
    flex-direction: column;
    align-items: stretch;
  }

  .row button {
    width: 100%;
    align-self: stretch;
  }

  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .modal-actions button {
    width: 100%;
  }
}

.selection-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border-secondary);
  border-radius: 10px;
  background: var(--bg-scrollable);
  margin-bottom: 1rem;
  min-height: 3rem;
}

.selection-btn {
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 4px;
  color: #fff;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.selection-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.selection-btn.red {
  background: #d32f2f;
}

.selection-btn.green {
  background: #388e3c;
}

.selection-btn.blue {
  background: #1976d2;
}

.selection-btn.yellow {
  background: #fbc02d;
  color: #1f1f1f;
}

.selection-btn.purple {
  background: #6a1b9a;
}

.selection-btn.black {
  background: #212121;
}

.edit-form {
  display: none;
  background: var(--bg-modal);
  border: 1px solid var(--border-secondary);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-form);
  margin: 1.25rem 0;
}

.edit-form.visible {
  display: block;
}

.edit-form-header {
  margin: 0 0 1.1rem;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
}

.edit-form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

.edit-form-actions button {
  min-width: 120px;
}

.edit-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: none;
  margin-bottom: 0.35rem;
}

.edit-form .field.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.edit-form .field.checkbox-field .checkbox-label {
  margin: 0;
}

.edit-form .field:last-child {
  margin-bottom: 0;
}

#loginModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--login-backdrop);
  z-index: 2000;
}

.login-modal-content {
  max-width: 400px;
  text-align: center;
}

.login-modal-content h2 {
  margin: 0 0 0.5rem;
  color: var(--text-primary);
  font-size: 1.5rem;
}

.login-description {
  margin: 0 0 1.5rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form .field {
  text-align: left;
}

.login-form button {
  margin-top: 0.5rem;
  padding: 0.75rem;
  font-size: 1.05rem;
}

.login-error {
  background: #fee;
  border: 1px solid #fcc;
  color: #c33;
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.logout-btn {
  margin-right: auto !important;
}

/* Help Modal Styles */
.help-modal-content {
  max-width: 600px;
}

.help-modal-content h2 {
  margin: 0 0 1.5rem;
  color: var(--text-primary);
  font-size: 1.5rem;
  text-align: center;
}

.help-section {
  margin-bottom: 1.5rem;
}

.help-section:last-of-type {
  margin-bottom: 1rem;
}

.help-section h3 {
  margin: 0 0 0.75rem;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
}

.help-section p {
  margin: 0.5rem 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.help-section p:first-of-type {
  margin-top: 0;
}

.help-examples {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.help-example {
  flex: 1;
  min-width: 140px;
  text-align: center;
}

.help-example .apparatus {
  margin: 0 auto 0.5rem;
  max-width: 140px;
}

.help-example p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
