/* ==========================================================================
   Magneten Møterom – Minimalist Dark Theme
   ========================================================================== */

:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --border: #e2e8e4;
  --border-focus: #83c14b;

  --text: #1a1f1c;
  --text-muted: #5e6c64;
  --text-subtle: #8a9b92;

  --accent: #83c14b;
  --accent-hover: #71a93e;
  --accent-muted: rgba(131, 193, 75, 0.15);

  --green: #83c14b;
  --green-muted: rgba(131, 193, 75, 0.12);
  --red: #ef4444;
  --red-muted: rgba(239, 68, 68, 0.1);
  --yellow: #f59e0b;

  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-logo {
  height: 24px;
  width: auto;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.accent {
  color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Status badge */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 100px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-subtle);
}

.status-badge.connected .status-dot { background: var(--green); }
.status-badge.connected { color: #166534; border-color: rgba(131, 193, 75, 0.3); background: rgba(131, 193, 75, 0.08); }

.status-badge.demo .status-dot { background: var(--yellow); }
.status-badge.demo { color: #854d0e; border-color: rgba(245, 158, 11, 0.3); background: rgba(245, 158, 11, 0.08); }

.status-badge.error .status-dot { background: var(--red); }
.status-badge.error { color: #991b1b; border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.08); }

.btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border-focus);
}

/* ==========================================================================
   Cards & Layout
   ========================================================================== */

.main {
  flex: 1;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.card-row .field + .field {
  margin-top: 0;
}

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

.card-header h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Room info bar */

.room-info {
  display: flex;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.15rem;
}

.room-info span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Quick dates */

.quick-dates {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.pill {
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pill:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

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

/* ==========================================================================
   Form Elements
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field + .field {
  margin-top: 0.85rem;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.input, .select {
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.input:focus, .select:focus {
  border-color: var(--accent);
}

.input.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

.select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8f9a' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.req { color: var(--red); }
.optional { color: var(--text-subtle); font-weight: 400; font-size: 0.72rem; }

.field-hint {
  font-size: 0.72rem;
  color: var(--text-subtle);
}

.field-error {
  font-size: 0.72rem;
  color: var(--red);
  min-height: 0.9rem;
}

/* ==========================================================================
   Slots Grid
   ========================================================================== */

.legend {
  display: flex;
  gap: 1rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.25rem;
  vertical-align: middle;
}

.dot-available { background: var(--green); }
.dot-busy { background: var(--text-subtle); }
.dot-past { background: var(--text-subtle); opacity: 0.5; }

.slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.slot {
  padding: 0.7rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.slot-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
  display: block;
}

.slot.available {
  border-color: rgba(34, 197, 94, 0.25);
  color: var(--text);
}

.slot.available .slot-label {
  color: var(--green);
}

.slot.available:hover {
  border-color: var(--green);
  background: var(--green-muted);
}

.slot.busy, .slot.past {
  color: var(--text-subtle);
  opacity: 0.45;
  cursor: default;
  border-color: transparent;
}

.slot.busy .slot-label, .slot.past .slot-label {
  color: var(--text-subtle);
}

.slots-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.slots-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-subtle);
  font-size: 0.82rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

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

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-subtle);
  color: var(--text);
}

.btn-sm {
  font-size: 0.78rem;
  padding: 0.5rem 0.85rem;
}

.btn-text {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

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

.btn-text.spinning svg {
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.full-width { width: 100%; }

.spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn.loading .btn-label { opacity: 0.6; }
.btn.loading .spinner { display: block; }

/* ==========================================================================
   Dialogs
   ========================================================================== */

.dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 440px;
  width: 92%;
  margin: auto;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: var(--text);
  animation: dialogIn 0.2s ease;
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dialog-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.15rem;
}

.dialog-top h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
}

.btn-close:hover { color: var(--text); }

/* Summary bar */

.summary-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 1.15rem;
}

.summary-sep {
  color: var(--text-subtle);
}

/* Modal alerts */

.modal-alert {
  display: none;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  line-height: 1.45;
  margin-bottom: 1.15rem;
  animation: fadeIn 0.2s ease;
}

.modal-alert:not([hidden]):not(:empty) {
  display: flex;
}

.modal-alert[hidden],
.modal-alert:empty {
  display: none !important;
}

.modal-alert-error {
  background: #fef2f2;
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #991b1b;
}

.modal-alert-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.modal-alert-content {
  flex: 1;
}

.modal-alert-title {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.modal-alert-desc {
  color: #7f1d1d;
  font-size: 0.8rem;
}

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

/* Success dialog */

.dialog-success {
  text-align: center;
}

.success-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--green-muted);
  color: var(--green);
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.85rem;
}

.dialog-success h3 {
  font-size: 1.2rem;
  margin-bottom: 0.3rem;
}

.receipt {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  margin: 1rem 0;
  font-size: 0.82rem;
}

.receipt-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.receipt-row:last-child { border-bottom: none; }
.receipt-row span:first-child { color: var(--text-muted); }
.receipt-row span:last-child { font-weight: 600; }

.cal-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.cal-actions .btn { flex: 1; }

/* ==========================================================================
   Toggle / Switch
   ========================================================================== */

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 0.5rem 0;
}

.toggle-row strong {
  font-size: 0.85rem;
  display: block;
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

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

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.15s;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch-track::before {
  transform: translateX(18px);
  background: #fff;
}

/* Test result */

.test-result {
  font-size: 0.78rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  margin-top: 0.4rem;
  display: none;
}

.test-result.success {
  display: block;
  background: var(--green-muted);
  color: #166534;
  border: 1px solid rgba(131, 193, 75, 0.3);
}

.test-result.error {
  display: block;
  background: var(--red-muted);
  color: #991b1b;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  max-width: 340px;
}

.toast {
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.toast-success { border-color: rgba(131, 193, 75, 0.4); color: #166534; background: rgba(131, 193, 75, 0.05); }
.toast.toast-error { border-color: rgba(239, 68, 68, 0.4); color: #991b1b; background: rgba(239, 68, 68, 0.05); }
.toast.toast-info { border-color: rgba(99, 102, 241, 0.4); color: #3730a3; background: rgba(99, 102, 241, 0.05); }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-subtle);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

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

  .quick-dates {
    flex-wrap: wrap;
  }

  .pill {
    flex: 1;
    text-align: center;
  }

  .cal-actions {
    flex-direction: column;
  }

  .summary-bar {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
}
