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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  padding: 16px;
  padding-bottom: 80px;
}

/* Telegram gate */
.tg-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.tg-gate-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.tg-gate-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--tg-theme-hint-color, #999);
}

form {
  max-width: 480px;
  margin: 0 auto;
}

section {
  margin-bottom: 24px;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--tg-theme-hint-color, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

label {
  display: block;
  font-size: 14px;
  color: var(--tg-theme-hint-color, #999);
  margin-bottom: 12px;
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 10px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  color: var(--tg-theme-text-color, #000);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  border-color: var(--tg-theme-button-color, #007aff);
}

input.invalid,
select.invalid {
  border-color: #ff3b30;
}

.error {
  color: #ff3b30;
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
  padding: 12px;
  background: rgba(255, 59, 48, 0.1);
  border-radius: 10px;
}

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23999' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* File upload */
.file-upload {
  margin-top: 4px;
}

.file-upload-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border: 2px dashed var(--tg-theme-hint-color, #ccc);
  border-radius: 10px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  cursor: pointer;
  transition: border-color 0.2s;
}

.file-upload-area:active {
  border-color: var(--tg-theme-button-color, #007aff);
}

.file-icon {
  font-size: 20px;
}

.file-text {
  font-size: 14px;
  color: var(--tg-theme-hint-color, #999);
}

.file-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--tg-theme-button-color, #007aff);
  border-radius: 10px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
}

.file-name {
  font-size: 14px;
  color: var(--tg-theme-text-color, #000);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 8px;
}

.file-remove {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--tg-theme-hint-color, #999);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

/* Upload progress */
.upload-progress {
  margin-top: 12px;
  text-align: center;
}

.upload-bar {
  width: 100%;
  height: 4px;
  background: var(--tg-theme-secondary-bg-color, #e5e5ea);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.upload-bar-inner {
  width: 0;
  height: 100%;
  background: var(--tg-theme-button-color, #007aff);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.upload-progress span {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
}

/* Navigation */
.twa-nav {
  max-width: 480px;
  margin: 0 auto 16px;
  padding: 8px 0;
}

.nav-link {
  display: inline-block;
  font-size: 14px;
  color: var(--tg-theme-link-color, #007aff);
  text-decoration: none;
  padding: 6px 0;
}

.nav-link:active {
  opacity: 0.6;
}

/* History filters */
.history-filters {
  max-width: 480px;
  margin: 0 auto 16px;
  padding: 12px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 10px;
}

.history-filters h2 {
  margin-bottom: 8px;
}

.history-filters label {
  margin-bottom: 8px;
}

.history-filters input[type="checkbox"] {
  display: inline;
  width: auto;
  margin-right: 6px;
  vertical-align: middle;
}

/* Generic button */
.btn {
  display: inline-block;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--tg-theme-button-text-color, #fff);
  background: var(--tg-theme-button-color, #007aff);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  margin-top: 4px;
}

.btn:active {
  opacity: 0.7;
}

/* History counter */
.history-counter {
  max-width: 480px;
  margin: 0 auto 8px;
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
}

/* History cards */
.history-card {
  max-width: 480px;
  margin: 0 auto 10px;
  padding: 12px;
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 10px;
  border-left: 3px solid transparent;
}

.history-card.has-slots {
  border-left-color: #34c759;
  background: rgba(52, 199, 89, 0.08);
}

.history-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.history-card-icon {
  font-size: 16px;
}

.history-card-time {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
}

.history-card-status {
  font-size: 13px;
  font-weight: 600;
  margin-left: auto;
}

.history-card.has-slots .history-card-status {
  color: #34c759;
}

.history-card-email {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 4px;
}

.history-card-toggle {
  font-size: 13px;
  color: var(--tg-theme-link-color, #007aff);
  cursor: pointer;
  margin-top: 8px;
  padding: 4px 0;
}

.history-card-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--tg-theme-hint-color, rgba(153,153,153,0.2));
}

.history-card-office {
  padding: 6px 0;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: space-between;
}

.history-card-office.has-slots {
  color: #34c759;
  font-weight: 600;
}

.office-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.office-status {
  text-align: right;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
}

.history-card-office.has-slots .office-status {
  color: #34c759;
}

.office-alert {
  width: 100%;
  font-size: 12px;
  color: var(--tg-theme-text-color, #000);
  white-space: pre-wrap;
  margin-top: 2px;
}

/* Load more */
.history-load-more {
  max-width: 480px;
  margin: 12px auto;
  text-align: center;
}
