:root {
  --bg:      var(--tg-theme-bg-color, #ffffff);
  --bg2:     var(--tg-theme-secondary-bg-color, #f4f5f7);
  --text:    var(--tg-theme-text-color, #1c1c1e);
  --hint:    var(--tg-theme-hint-color, #8e8e93);
  --btn:     var(--tg-theme-button-color, #007aff);
  --btn-txt: var(--tg-theme-button-text-color, #ffffff);
  --err:     #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --r:       14px;
  --r-sm:    10px;
  --app-height: var(--tg-viewport-stable-height, var(--tg-viewport-height, 100svh));
  --app-safe-bottom: var(--tg-content-safe-area-inset-bottom, var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  
  /* Premium Design Variables */
  --border-color: rgba(127, 127, 127, 0.12);
  --card-bg: var(--tg-theme-bg-color, #ffffff);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.05);
  --glow-color: rgba(0, 122, 255, 0.12);
}

/* Detect dark mode from telegram background color to tweak gradients and borders */
@media (prefers-color-scheme: dark) {
  :root {
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* Progress bar */
.progress {
  height: 4px;
  background: var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--btn), #5856d6);
  border-radius: 0 2px 2px 0;
  transition: width .3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sections */
.header {
  padding: 24px 20px 8px;
}
.header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.header p {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
}
.section {
  display: none;
  padding-bottom: 130px;
  animation: fadeIn 0.3s ease;
}
.section.active {
  display: block;
}

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

/* Groups and Controls */
.group {
  padding: 16px 20px 0;
}
label {
  display: block;
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.required::after {
  content: ' *';
  color: var(--err);
}

input, select, textarea {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  color: var(--text);
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
input[type="date"] {
  -webkit-appearance: auto;
  appearance: auto;
}
input:focus, select:focus {
  border-color: var(--btn);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--glow-color);
}
input.err, select.err {
  border-color: var(--err);
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

/* Error Messages with smooth transition */
.err-msg {
  font-size: 12px;
  color: var(--err);
  margin-top: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, margin-top 0.2s ease;
}
.err-msg.show {
  max-height: 120px;
  opacity: 1;
  margin-top: 6px;
}

.submit-error-box {
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.28);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--err);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}
.submit-error-icon {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.hint {
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
  line-height: 1.4;
}
#arrivalBufferDaysHint {
  white-space: pre-line;
}

/* Radio buttons & Checkboxes */
.radio-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.radio-row input {
  display: none;
}
.radio-row label {
  padding: 12px 16px;
  border-radius: var(--r);
  background: var(--bg2);
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  border: 1px solid var(--border-color);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
  box-shadow: var(--shadow-sm);
}
.radio-row label:active {
  transform: scale(0.98);
}
.radio-row.two label {
  flex: 1;
  text-align: center;
}
.radio-row input:checked + label {
  background: var(--btn);
  color: var(--btn-txt);
  border-color: var(--btn);
}
.radio-row input:disabled + label {
  opacity: .5;
  cursor: default;
}
.radio-row.err label {
  border-color: var(--err);
}

/* Premium Radio Cards */
.radio-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}
.radio-card {
  position: relative;
}
.radio-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.radio-card-label {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
  box-shadow: var(--shadow-sm);
}
.radio-card-label:active {
  transform: scale(0.99);
}
.radio-card-icon {
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(0, 122, 255, 0.06);
  border-radius: 12px;
  transition: background 0.2s ease, transform 0.2s ease;
}
.radio-card-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.radio-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  transition: color 0.2s ease;
}
.radio-card-desc {
  font-size: 12px;
  color: var(--hint);
  line-height: 1.35;
}
.radio-card-dot {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 50%;
  position: relative;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  flex-shrink: 0;
}
.radio-card-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 10px;
  height: 10px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

/* Checked state */
.radio-card input[type="radio"]:checked + .radio-card-label {
  border-color: var(--btn);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--glow-color), var(--shadow-md);
}
.radio-card input[type="radio"]:checked + .radio-card-label .radio-card-icon {
  background: rgba(0, 122, 255, 0.15);
  transform: scale(1.05);
}
.radio-card input[type="radio"]:checked + .radio-card-label .radio-card-title {
  color: var(--btn);
}
.radio-card input[type="radio"]:checked + .radio-card-label .radio-card-dot {
  border-color: var(--btn);
  background-color: var(--btn);
}
.radio-card input[type="radio"]:checked + .radio-card-label .radio-card-dot::after {
  transform: translate(-50%, -50%) scale(1);
}

/* Disabled state */
.radio-card input[type="radio"]:disabled + .radio-card-label {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

/* Error state */
.radio-cards.err .radio-card-label {
  border-color: var(--err);
}

.divider {
  height: 1px;
  background: var(--border-color);
  margin: 20px 0 0;
}
.sub-label {
  padding: 16px 20px 0;
  font-size: 11px;
  color: var(--hint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* Navigation Bar */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 12px));
  display: flex;
  gap: 12px;
  z-index: 90;
}

/* Adjust navigation bar background in dark theme */
@media (prefers-color-scheme: dark) {
  .nav {
    background: rgba(28, 28, 30, 0.85);
  }
}

button {
  font-family: inherit;
}

.btn-back {
  width: 90px;
  height: 50px;
  padding: 0 16px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: transform 0.1s ease, background 0.15s ease;
}
.btn-back:active {
  transform: scale(0.97);
}

.btn-next {
  flex: 1;
  height: 50px;
  padding: 0 16px;
  background: linear-gradient(135deg, var(--btn), #0056b3);
  border: none;
  border-radius: var(--r);
  color: var(--btn-txt);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: transform 0.1s ease, opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}
.btn-next:active {
  transform: scale(0.97);
}
.btn-next:disabled {
  opacity: .5;
  cursor: default;
  box-shadow: none;
}

/* Start screen */
.start {
  padding: 32px 16px 24px;
  display: flex;
  flex-direction: column;
  min-height: var(--app-height);
  box-sizing: border-box;
}
.start-logo {
  width: 76px;
  height: 76px;
  background: linear-gradient(135deg, rgba(0, 122, 255, 0.12), rgba(52, 199, 89, 0.08));
  border: 1px solid rgba(0, 122, 255, 0.18);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.start-logo:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 122, 255, 0.18);
}
.start-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}
.start-sub {
  font-size: 14px;
  color: var(--hint);
  text-align: center;
  line-height: 1.5;
  margin: 0 auto 28px;
  max-width: 320px;
}
.start-note {
  font-size: 12px;
  color: var(--hint);
  text-align: center;
  line-height: 1.5;
  margin: 28px auto 0;
  max-width: 320px;
  padding: 12px;
  border-radius: var(--r-sm);
  border: 1px dashed var(--border-color);
  background: rgba(127, 127, 127, 0.02);
}

.btn-start {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  background: linear-gradient(135deg, var(--btn), #0056b3);
  border: none;
  border-radius: var(--r);
  color: var(--btn-txt);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition: transform 0.1s ease;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}
.btn-start:active {
  transform: scale(0.97);
}

/* Applicant lists & cards */
.applicant-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  width: 100%;
}
.applicant-list:empty {
  display: none;
}
.list-loading,
.list-error {
  text-align: center;
  padding: 14px 16px;
  border-radius: var(--r);
  font-size: 14px;
  line-height: 1.45;
}
.list-loading {
  color: var(--hint);
  background: rgba(127, 127, 127, 0.06);
  border: 1px solid var(--border-color);
}
.list-error {
  color: var(--err);
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.28);
}
.list-error-retry {
  margin-top: 10px;
  border: none;
  background: transparent;
  color: var(--btn);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
/* Tabs Container */
.tabs-container {
  display: flex;
  background: var(--bg2);
  border-radius: var(--r-sm);
  padding: 4px;
  gap: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--border-color);
}

/* Individual Tab Button */
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: calc(var(--r-sm) - 2px);
  color: var(--hint);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

/* Active Tab */
.tab-btn.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Badge inside Tab */
.tab-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  background: var(--border-color);
  color: var(--hint);
  border-radius: 10px;
  transition: all 0.2s ease;
}

.tab-btn.active .tab-badge {
  background: var(--btn);
  color: var(--btn-txt);
}

.tab-badge.err {
  background: rgba(255, 59, 48, 0.1);
  color: var(--err);
}

.tab-btn.active .tab-badge.err {
  background: var(--err);
  color: #ffffff;
}

/* Applicant Search */
.applicant-search {
  margin-bottom: 12px;
}
.applicant-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--r-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.applicant-search input:focus {
  border-color: var(--btn);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

/* Tab Content */
.tab-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Empty State */
.tab-empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--hint);
  font-size: 14px;
  border: 1px dashed var(--border-color);
  border-radius: var(--r);
  background: rgba(127, 127, 127, 0.02);
}
.applicant-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}
.applicant-card:active {
  transform: scale(0.99);
}
.applicant-card-info {
  width: 100%;
}
.applicant-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.applicant-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}
.applicant-country-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
.form-country-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  color: var(--text);
  vertical-align: middle;
  margin-left: 6px;
}
.applicant-card-meta {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.45;
  margin-bottom: 0;
  word-break: break-word;
}
.applicant-meta-status {
  margin-bottom: 4px;
}
.applicant-card-error {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.22);
  color: var(--err);
  font-size: 12.5px;
  line-height: 1.4;
  word-break: break-word;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.applicant-card-error-icon {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1.2;
}
.applicant-card-error-text {
  flex: 1;
  min-width: 0;
}
.applicant-meta-params {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.applicant-meta-extra {
  font-size: 12.5px;
  color: var(--hint);
  margin-top: 3px;
}
.applicant-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}
.btn-small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-align: center;
  padding: 9px 12px;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.applicant-actions .btn-small {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  height: 38px;
}
.applicant-actions .btn-small.primary {
  flex: 1 1 100%;
  width: 100%;
}
.btn-small:active {
  transform: scale(0.97);
}
.btn-small.primary {
  background: var(--btn);
  color: var(--btn-txt);
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.15);
}
.btn-small.danger {
  background: transparent;
  color: var(--err);
  border: 1px solid rgba(255, 59, 48, 0.3);
}
.btn-small.danger:active {
  background: rgba(255, 59, 48, 0.05);
}

/* Periods selection */
.add-period-btn {
  margin-top: 10px;
  width: 100%;
  background: var(--bg2);
  color: var(--btn);
  border: 1px dashed var(--btn);
  padding: 12px;
  font-weight: 600;
  border-radius: var(--r);
  transition: background 0.2s ease, transform 0.1s ease;
}
.add-period-btn:active {
  background: rgba(0, 122, 255, 0.05);
  transform: scale(0.98);
}
.period-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
  animation: periodSlideDown 0.2s ease;
}

@keyframes periodSlideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.period-col {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.period-col label {
  font-size: 9px;
  margin-bottom: 3px;
  padding: 0 4px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.period-col input {
  padding: 10px 12px;
  border-radius: var(--r-sm);
}
.period-del {
  background: rgba(255, 59, 48, 0.08);
  color: var(--err);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 12px;
  transition: transform 0.1s ease, background 0.15s ease;
}
.period-del:active {
  transform: scale(0.9);
  background: rgba(255, 59, 48, 0.15);
}
.period-placeholder {
  width: 38px;
  margin-top: 12px;
}

/* Queue preview style */
.queue-preview {
  margin-top: 12px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s ease;
}
.queue-preview-header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  background: var(--bg2);
  border-bottom: 1px solid var(--border-color);
}
.queue-preview-body {
  padding: 12px 16px;
  color: var(--hint);
  font-size: 13px;
  line-height: 1.5;
}
.queue-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.08);
  color: var(--text);
  font-size: 14px;
}
.queue-row:last-of-type {
  border-bottom: none;
}
.queue-row span:last-child {
  font-weight: 700;
  color: var(--btn);
}

/* Days Buffer segment & scale selector */
.days-picker {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  gap: 8px;
  align-items: center;
}
.days-picker input {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  background: var(--bg2);
}
.days-step {
  height: 46px;
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  background: var(--bg2);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.days-step:active {
  transform: translateY(1px) scale(0.95);
  background: rgba(127, 127, 127, 0.05);
}

.days-scale {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 12px;
  background: var(--bg2);
  padding: 4px;
  border-radius: var(--r);
  border: 1px solid var(--border-color);
}
.days-scale button {
  height: 32px;
  border: none;
  border-radius: calc(var(--r) - 4px);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, font-weight 0.2s ease, box-shadow 0.2s ease;
}
.days-scale button.active {
  background: var(--btn);
  color: var(--btn-txt);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* Done and Error screens */
.done {
  padding: 64px 24px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}
.done .icon {
  font-size: 64px;
  width: 96px;
  height: 96px;
  background: rgba(52, 199, 89, 0.1);
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}
.done h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
}
.done p {
  color: var(--hint);
  line-height: 1.5;
  max-width: 280px;
  margin: 0 auto;
}

.telegram-required {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 24px;
  text-align: center;
}
.telegram-required-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.telegram-required h2 {
  margin-bottom: 8px;
  font-weight: 700;
}
.telegram-required p {
  color: var(--hint);
  max-width: 320px;
  line-height: 1.5;
}
.telegram-required a {
  margin-top: 20px;
  display: inline-block;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--btn), #0056b3);
  color: var(--btn-txt);
  border-radius: var(--r);
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}

@media (max-height: 639px) {
  .start { padding-top: 24px; }
  .start-logo { font-size: 32px; width: 60px; height: 60px; margin-bottom: 14px; }
  .start-sub { margin-bottom: 20px; }
  .start-note { margin-top: 20px; }
}

/* Maintenance Cards */
.maintenance-card {
  background: rgba(255, 59, 48, 0.05);
  border-left: 4px solid var(--err);
  border-top: 1px solid rgba(255, 59, 48, 0.1);
  border-right: 1px solid rgba(255, 59, 48, 0.1);
  border-bottom: 1px solid rgba(255, 59, 48, 0.1);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--r);
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
  margin: 16px 0;
  box-shadow: var(--shadow-sm);
}
.maintenance-card-title {
  font-weight: 700;
  color: var(--err);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Queue warning styles */
.queue-row-warning span:first-child {
  color: var(--warning);
}
.queue-warning-badge {
  margin-left: 6px;
  cursor: help;
}
.queue-warning-box {
  background: rgba(255, 149, 0, 0.08);
  border-left: 4px solid var(--warning);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  line-height: 1.4;
  margin-top: 12px;
}

/* ── Bottom add button (in-flow for Telegram Mini App viewport) ─────────────── */
.sticky-add-btn {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  margin-left: -24px;
  margin-right: -24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  padding: 12px 20px calc(12px + var(--app-safe-bottom));
  z-index: 90;
  box-sizing: border-box;
}

@supports not (background: color-mix(in srgb, white 50%, transparent)) {
  .sticky-add-btn {
    background: rgba(255, 255, 255, 0.92);
  }
  @media (prefers-color-scheme: dark) {
    .sticky-add-btn {
      background: rgba(28, 28, 30, 0.92);
    }
  }
}

/* ── Timeline bottom-sheet ────────────────────────────────────────────────── */
.timeline-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}
.timeline-overlay.closing {
  animation: fadeOut 0.25s ease forwards;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.timeline-sheet {
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  animation: sheetSlideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 12px);
}
.timeline-sheet.closing {
  animation: sheetSlideDown 0.25s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes sheetSlideDown {
  from { transform: translateY(0); }
  to   { transform: translateY(100%); }
}

.timeline-handle {
  width: 36px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.timeline-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.timeline-close-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--bg2);
  border-radius: 50%;
  color: var(--hint);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.timeline-close-btn:active { background: var(--border-color); }

.timeline-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* History button on cards */
.btn-small.history {
  background: var(--bg2);
  color: var(--hint);
  border: 1px solid var(--border-color);
  font-weight: 500;
}
.btn-small.history:active { background: var(--border-color); }

/* Timeline vertical list */
.timeline-list {
  position: relative;
  padding-left: 28px;
}
.timeline-list::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: var(--border-color);
  border-radius: 1px;
}
.timeline-item {
  position: relative;
  margin-bottom: 22px;
  animation: fadeIn 0.2s ease both;
}
.timeline-item:last-child { margin-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -23px;
  top: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--btn);
  background: var(--bg);
}
.timeline-item.type-booked .timeline-dot   { background: var(--success); border-color: var(--success); }
.timeline-item.type-error  .timeline-dot   { background: var(--err);     border-color: var(--err); }
.timeline-item.type-created .timeline-dot  { background: var(--hint);    border-color: var(--hint); }

.timeline-item-date {
  font-size: 11px;
  color: var(--hint);
  font-weight: 500;
  margin-bottom: 2px;
}
.timeline-item-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.timeline-item.type-booked .timeline-item-label { color: var(--success); }
.timeline-item.type-error  .timeline-item-label { color: var(--err); }

.timeline-item-detail {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
  line-height: 1.4;
}
.timeline-loading,
.timeline-empty {
  text-align: center;
  padding: 28px 0;
  color: var(--hint);
  font-size: 14px;
}

/* ── Link Info ───────────────────────────────────────────────────────────────── */
.vms-link-info {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  color: var(--fg);
  animation: fadeIn 0.2s ease;
}
.vms-link-info-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.vms-link-info.loading {
  color: var(--hint);
}
.vms-link-info.success {
  background: rgba(0, 146, 70, 0.08);
  border-color: rgba(0, 146, 70, 0.3);
  color: #007a3b;
}
.vms-link-info.err {
  background: rgba(205, 33, 42, 0.08);
  border-color: rgba(205, 33, 42, 0.3);
  color: #cd212a;
}

/* ── Heatmap ────────────────────────────────────────────────────────────────── */
.heatmap-container {
  margin-top: 14px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r);
  padding: 12px 14px 14px;
  animation: fadeIn 0.25s ease;
}
.heatmap-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.heatmap-legend {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.heatmap-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--hint);
}
.heatmap-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.heatmap-legend-dot.green {
  background: rgba(52, 199, 89, 0.65);
}
.heatmap-legend-dot.yellow {
  background: rgba(255, 149, 0, 0.65);
}
.heatmap-legend-dot.red {
  background: rgba(255, 59, 48, 0.65);
}
.heatmap-legend-dot.past {
  background: rgba(142, 142, 147, 0.35);
}
.calendar-months {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.calendar-month {
  margin-top: 6px;
}
.calendar-month-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 8px;
  padding-left: 2px;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  text-align: center;
}
.calendar-weekdays span {
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
}
.calendar-weekdays span.weekend-head {
  color: var(--hint);
  opacity: 0.5;
}
.calendar-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-day {
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  box-sizing: border-box;
  user-select: none;
}
.calendar-day.empty {
  visibility: hidden;
}
.calendar-day.weekend {
  background: transparent;
  color: var(--hint);
  opacity: 0.35;
}
.calendar-day.out-of-range {
  background: transparent;
  color: var(--hint);
  opacity: 0.2;
}
.calendar-day.past {
  background: rgba(142, 142, 147, 0.12);
  color: var(--hint);
  opacity: 0.7;
}
.calendar-day.green {
  background: rgba(52, 199, 89, 0.35);
  border: 1px solid rgba(52, 199, 89, 0.65);
}
.calendar-day.yellow {
  background: rgba(255, 149, 0, 0.35);
  border: 1px solid rgba(255, 149, 0, 0.65);
}
.calendar-day.red {
  background: rgba(255, 59, 48, 0.30);
  border: 1px solid rgba(255, 59, 48, 0.55);
  box-sizing: border-box;
}
.heatmap-legend-dot.past,
.heatmap-day.past {
  background: rgba(120, 120, 128, 0.14);
  border: 1px solid rgba(120, 120, 128, 0.22);
  box-sizing: border-box;
}

/* ── Country Selector Modal & Cards ────────────────────────────────────── */
.country-sheet-body {
  padding: 14px 18px 24px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.country-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.country-card {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--bg2);
  border: 1px solid var(--border-color);
  border-radius: var(--r-sm);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.country-card-active {
  cursor: pointer;
}

.country-card-active:hover {
  border-color: var(--btn);
}

.country-card-active:active {
  transform: scale(0.98);
  background: rgba(0, 122, 255, 0.08);
  border-color: var(--btn);
}

.country-card-disabled {
  opacity: 0.62;
  cursor: default;
}

.country-card-flag {
  font-size: 26px;
  line-height: 1;
  margin-right: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}

.country-card-info {
  flex: 1;
  min-width: 0;
}

.country-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.country-card-provider {
  font-size: 12px;
  font-weight: 500;
  color: var(--hint);
  line-height: 1.35;
}

.country-card-centers {
  font-size: 11px;
  color: var(--hint);
  opacity: 0.85;
  line-height: 1.35;
  margin-top: 3px;
  word-break: break-word;
}

.country-card-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  margin-left: 10px;
  color: var(--hint);
  opacity: 0.45;
  transition: transform 0.15s ease, opacity 0.15s ease, color 0.15s ease;
}

.country-card-active:hover .country-card-arrow,
.country-card-active:active .country-card-arrow {
  opacity: 1;
  color: var(--btn);
  transform: translateX(2px);
}

.country-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.2px;
  flex-shrink: 0;
  margin-left: 10px;
  margin-top: 2px;
}

.country-card-badge.badge-active {
  background: rgba(52, 199, 89, 0.15);
  color: var(--success);
}

.country-card-badge.badge-soon {
  background: rgba(142, 142, 147, 0.16);
  color: var(--hint);
}
