:root {
  color-scheme: dark;
  --page-bg: #06081d;
  --page-bg-glow-a: rgba(95, 102, 255, 0.26);
  --page-bg-glow-b: rgba(27, 114, 255, 0.16);
  --shell-border: #272d5e;
  --shell-shadow: 0 30px 60px rgba(3, 5, 17, 0.52);

  --rail-bg: #e9eaf0;
  --rail-border: #c8ccda;
  --rail-text: #1f2433;
  --rail-muted: #5b6378;
  --rail-button-bg: #ffffff;
  --rail-button-border: #c6cbe0;
  --rail-button-hover: #f6f8ff;

  --panel-bg: #14173c;
  --panel-bg-alt: #1c2152;
  --panel-border: #343b78;
  --text: #f4f5ff;
  --text-muted: #b8bedf;
  --accent: #8161ff;
  --accent-strong: #5e45d5;
  --accent-text: #fdfdff;
  --ok-bg: rgba(66, 193, 124, 0.28);
  --ok-text: #c4f8d8;
  --warn-bg: rgba(244, 168, 92, 0.3);
  --warn-text: #ffe0bf;
  --bad-bg: rgba(237, 97, 124, 0.3);
  --bad-text: #ffd1dc;

  --radius-lg: 22px;
  --radius-md: 15px;
}

:root[data-theme="light"] {
  --rail-bg: #ececf2;
  --rail-border: #ccd1df;
}

:root[data-theme="dark"] {
  --rail-bg: #dfe2ec;
  --rail-border: #c2c8d8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "SF Pro Text", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 2%, var(--page-bg-glow-a), transparent 34%),
    radial-gradient(circle at 88% 0%, var(--page-bg-glow-b), transparent 38%),
    var(--tg-bg, var(--page-bg));
  color: var(--text);
}

body {
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top, 0px) + 10px)
    10px
    calc(env(safe-area-inset-bottom, 0px) + 10px);
}

.app-shell {
  width: min(1120px, 100%);
  min-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(240px, 285px) 1fr;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shell-shadow);
  background: linear-gradient(180deg, #0b0e29, #0d0f2f);
}

.brand-rail {
  background: var(--rail-bg);
  color: var(--rail-text);
  border-right: 1px solid var(--rail-border);
  padding: 26px 18px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  position: relative;
  width: 20px;
  height: 20px;
  display: inline-block;
}

.dot {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.dot-orange {
  left: 0;
  top: 5px;
  background: #f58235;
}

.dot-coral {
  left: 6px;
  top: -1px;
  width: 8px;
  height: 8px;
  background: #f06055;
}

.dot-yellow {
  right: 0;
  bottom: 0;
  width: 9px;
  height: 9px;
  background: #f7b933;
}

.dot-blue {
  right: -2px;
  bottom: -4px;
  width: 6px;
  height: 6px;
  background: #5359d5;
}

.brand-name {
  margin: 0;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: 0.08em;
  color: #191e2d;
}

.rail-caption {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rail-muted);
}

.brand-rail .panel {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.brand-rail .panel-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rail-muted);
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.brand-rail .menu-grid button {
  border: 1px solid var(--rail-button-border);
  background: var(--rail-button-bg);
  color: var(--rail-text);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  font-size: 15px;
  font-weight: 620;
}

.brand-rail .menu-grid button:hover {
  background: var(--rail-button-hover);
}

.workspace {
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto auto minmax(240px, 1fr) auto;
  gap: 12px;
}

.hero {
  position: relative;
  border-radius: 18px;
  border: 1px solid #3f4788;
  overflow: hidden;
  min-height: 225px;
  background: linear-gradient(170deg, #0d1b5a 0%, #0b113f 52%, #100c38 100%);
}

.hero::before {
  content: "";
  position: absolute;
  inset: -55% -20% -30%;
  background:
    repeating-linear-gradient(
      -18deg,
      rgba(126, 143, 255, 0) 0 27px,
      rgba(139, 116, 255, 0.92) 28px 33px,
      rgba(70, 125, 255, 0.76) 34px 39px,
      rgba(126, 143, 255, 0) 40px 68px
    );
  opacity: 0.8;
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 12, 41, 0.2) 0%, rgba(11, 11, 38, 0.75) 72%);
}

.hero-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 18px;
}

.overline {
  margin: 0;
  font-size: 12px;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #acb5ff;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4.2vw, 52px);
  line-height: 1.06;
  letter-spacing: 0.01em;
  color: #ffffff;
}

.subtitle {
  margin: 0;
  color: #d9ddff;
  font-size: 22px;
  max-width: 700px;
}

.workspace .panel,
.cards-wrapper {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 28px rgba(4, 6, 20, 0.45);
}

.workspace .panel {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.workspace .panel-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.workspace .panel-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="search"] {
  width: 100%;
  border: 1px solid #434b8f;
  border-radius: 12px;
  background: var(--panel-bg-alt);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
}

input[type="time"] {
  width: 100%;
  border: 1px solid #434b8f;
  border-radius: 10px;
  background: var(--panel-bg-alt);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
}

input[type="time"]:focus {
  outline: 2px solid rgba(129, 97, 255, 0.45);
  outline-offset: 1px;
}

input[type="search"]::placeholder {
  color: var(--text-muted);
}

input[type="search"]:focus {
  outline: 2px solid rgba(129, 97, 255, 0.45);
  outline-offset: 1px;
}

button {
  border: 1px solid #444b90;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel-bg-alt);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: #242a63;
}

button:active {
  transform: translateY(1px);
}

#clear-search {
  min-width: 42px;
  font-size: 20px;
  line-height: 1;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#records-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 620;
}

.cards-wrapper {
  padding: 10px;
  max-height: clamp(260px, 43dvh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cards-wrapper::-webkit-scrollbar {
  width: 8px;
}

.cards-wrapper::-webkit-scrollbar-thumb {
  border-radius: 8px;
  background: rgba(158, 166, 235, 0.38);
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  background: linear-gradient(180deg, rgba(34, 42, 95, 0.8), rgba(27, 32, 78, 0.88));
  border: 1px solid #424a8d;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.card-line {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.status-chip {
  font-size: 12px;
  line-height: 1;
  padding: 7px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-approved {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-cancelled {
  background: var(--bad-bg);
  color: var(--bad-text);
}

.card-footer {
  display: flex;
  justify-content: flex-end;
}

.ghost-btn {
  background: transparent;
}

.actions {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom, 0px));
  z-index: 3;
}

.calendar-panel {
  gap: 12px;
}

.calendar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.calendar-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 10px;
}

.control-group {
  background: rgba(23, 29, 77, 0.7);
  border: 1px solid #3c458a;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.control-label {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.location-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.location-chip {
  border-radius: 999px;
  padding: 8px 10px;
  border: 1px solid #4853a3;
  background: rgba(28, 35, 89, 0.95);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.location-chip.is-active {
  border-color: #8e70ff;
  background: linear-gradient(145deg, rgba(129, 97, 255, 0.25), rgba(94, 69, 213, 0.45));
}

.time-inputs {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.calendar-nav {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
}

#calendar-month-label {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calendar-weekdays span {
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-pad {
  min-height: 46px;
  border-radius: 10px;
  background: rgba(18, 23, 66, 0.5);
  border: 1px dashed rgba(77, 87, 163, 0.35);
}

.calendar-day {
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid #4b54a3;
  background: rgba(33, 40, 99, 0.9);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  padding: 6px 2px;
}

.calendar-day .day-marker {
  font-size: 12px;
  line-height: 1;
}

.calendar-day .day-num {
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.calendar-day.status-green {
  border-color: rgba(65, 194, 124, 0.62);
}

.calendar-day.status-yellow {
  border-color: rgba(244, 168, 92, 0.72);
}

.calendar-day.status-red {
  border-color: rgba(237, 97, 124, 0.72);
}

.calendar-day.is-selected {
  box-shadow: 0 0 0 2px rgba(142, 112, 255, 0.75);
}

.calendar-day.is-past {
  opacity: 0.48;
}

.calendar-day:disabled {
  cursor: not-allowed;
}

.calendar-selection {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.calendar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.slot-result {
  margin: 0;
  border: 1px solid #414a97;
  border-radius: 12px;
  padding: 10px;
  background: rgba(23, 29, 77, 0.65);
  color: var(--text-muted);
  font-size: 14px;
  white-space: pre-line;
}

.slot-result[data-tone="success"] {
  border-color: rgba(66, 193, 124, 0.7);
  color: var(--ok-text);
}

.slot-result[data-tone="warn"] {
  border-color: rgba(244, 168, 92, 0.8);
  color: var(--warn-text);
}

.slot-result[data-tone="error"] {
  border-color: rgba(237, 97, 124, 0.85);
  color: var(--bad-text);
}

.primary {
  border-color: #8e70ff;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: var(--accent-text);
}

.primary:hover {
  filter: brightness(1.06);
}

.empty-state {
  margin: 0;
  border: 1px dashed #4f579c;
  border-radius: 12px;
  background: rgba(29, 35, 83, 0.65);
  padding: 18px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .brand-rail {
    border-right: 0;
    border-bottom: 1px solid var(--rail-border);
    padding: 16px 14px;
  }

  .workspace {
    padding: 12px;
    grid-template-rows: auto auto auto minmax(260px, 1fr) auto;
  }

  .subtitle {
    font-size: 19px;
  }

  .calendar-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding: 0;
  }

  .app-shell {
    width: 100%;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .brand-name {
    font-size: 22px;
  }

  .hero {
    min-height: 200px;
  }

  .calendar-nav {
    grid-template-columns: 38px 1fr 38px;
  }

  .calendar-day,
  .calendar-pad {
    min-height: 42px;
  }

  .time-inputs {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}
