/* ─── Telegram WebApp Theme Integration ────────────────────────────── */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2678b6);
  --btn: var(--tg-theme-button-color, #2678b6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --section-header: var(--tg-theme-section-header-text-color, #7d7d7d);
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ─── Header ───────────────────────────────────────────────────────── */

.header {
  padding: 16px 20px 8px;
  text-align: center;
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
}

.subtitle {
  color: var(--hint);
  font-size: 13px;
}

/* ─── Tabs ─────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 0;
  padding: 8px 16px;
  position: sticky;
  top: 0;
  background: var(--secondary-bg);
  z-index: 10;
}

.tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab.active {
  color: var(--btn);
  border-bottom-color: var(--btn);
}

/* ─── Tab Content ──────────────────────────────────────────────────── */

.tab-content {
  display: none;
  padding: 8px 16px 24px;
}

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

/* ─── Cards ────────────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card-label {
  color: var(--hint);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
}

/* ─── Lists ────────────────────────────────────────────────────────── */

h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--section-header);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

.list {
  background: var(--section-bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--secondary-bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-left {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-subtitle {
  color: var(--hint);
  font-size: 12px;
  margin-top: 2px;
}

.list-item-right {
  text-align: right;
  flex-shrink: 0;
  margin-left: 12px;
}

.list-item-value {
  font-weight: 600;
  font-size: 14px;
}

.list-item-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red { background: #fee2e2; color: #991b1b; }

.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--hint);
}

/* ─── Toolbar ──────────────────────────────────────────────────────── */

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

/* ─── Buttons ──────────────────────────────────────────────────────── */

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--secondary-bg);
  color: var(--text);
}

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

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ─── Forms ────────────────────────────────────────────────────────── */

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 4px;
}

.field input[type="text"],
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--secondary-bg);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--btn);
}

.field input[type="checkbox"] {
  margin-right: 6px;
}

.setting-value {
  font-size: 16px;
  font-weight: 600;
}

.hint {
  color: var(--hint);
  font-size: 13px;
}

.hint a {
  color: var(--link);
}

/* ─── Modal ────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

/* ─── Action Grid ──────────────────────────────────────────────────── */

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}

.action-icon {
  font-size: 22px;
}

.btn-reboot {
  background: #fee2e2;
  color: #991b1b;
}

.hidden {
  display: none !important;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
}

.modal-content h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

/* ─── Project Card Actions ─────────────────────────────────────────── */

.project-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.project-actions button {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  background: var(--secondary-bg);
  color: var(--text);
}
