:root {
  --bg: #f5f5f7;
  --card-bg: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #e5e5ea;
  --accent: #007aff;
  --accent-green: #30d158;
  --accent-yellow: #ffd60a;
  --accent-red: #ff453a;
  --accent-blue: #64d2ff;
  --progress-bg: #e5e5ea;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --card-bg: #1c1c1e;
    --text: #f5f5f7;
    --text-secondary: #8e8e93;
    --border: #2c2c2e;
    --accent: #0a84ff;
    --accent-green: #30d158;
    --accent-yellow: #ffd60a;
    --accent-red: #ff453a;
    --accent-blue: #64d2ff;
    --progress-bg: #2c2c2e;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ===== Login Screen ===== */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.pin-display {
  display: flex;
  gap: 12px;
  margin-bottom: 0.5rem;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-secondary);
  transition: all 0.15s;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-error {
  color: var(--accent-red);
  font-size: 0.85rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 12px;
  margin-top: 0.5rem;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.pin-key:active {
  transform: scale(0.92);
  background: var(--border);
}

.pin-key-empty {
  visibility: hidden;
}

.pin-key-del {
  font-size: 1.3rem;
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.header-right {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { background: var(--border); }
.icon-btn.active { color: var(--accent); }

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.connection-dot.online { background: var(--accent-green); }
.connection-dot.offline { background: var(--accent-red); }

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  margin: 8px 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

/* ===== Metrics ===== */
.metric-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.metric-row:last-child { margin-bottom: 0; }

.metric-label {
  font-size: 0.85rem;
  font-weight: 500;
  width: 48px;
  flex-shrink: 0;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--progress-bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent-green);
  transition: width 0.5s ease, background 0.3s;
  width: 0%;
}

.progress-fill.warn { background: var(--accent-yellow); }
.progress-fill.danger { background: var(--accent-red); }

.metric-value {
  font-size: 0.8rem;
  font-weight: 600;
  width: 42px;
  text-align: right;
  flex-shrink: 0;
}

.metric-value-full {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-left: auto;
}

/* ===== Usage ===== */
.usage-label {
  width: auto;
  min-width: 48px;
  font-size: 0.8rem;
}

.usage-reset {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin: -4px 0 8px 0;
  padding-left: 0;
}

.usage-extra-row {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

.usage-extra-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.usage-extra-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ===== Session List ===== */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.session-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.session-uptime {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.session-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.session-detail code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.72rem;
  background: var(--card-bg);
  padding: 1px 4px;
  border-radius: 3px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.active { background: var(--accent-green); }
.status-dot.waiting { background: var(--accent-yellow); animation: pulse 1.5s infinite; }
.status-dot.finished { background: var(--accent-blue); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* tmux items */
.tmux-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.tmux-item:not(:last-child) { border-bottom: 1px solid var(--border); }

.tmux-name { font-weight: 500; font-size: 0.9rem; }

.tmux-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.tmux-badge.attached { background: var(--accent-green); color: #000; }
.tmux-badge.detached { background: var(--border); color: var(--text-secondary); }

.tmux-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tmux-kill {
  background: none;
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.tmux-kill:active { opacity: 1; background: var(--accent-red); color: #fff; }

/* ===== Events ===== */
.events-list {
  max-height: 300px;
  overflow-y: auto;
}

.event-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--border);
}

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

.event-time {
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.event-type {
  font-weight: 600;
  white-space: nowrap;
}

.event-type.stop { color: var(--accent-blue); }
.event-type.idle { color: var(--accent-yellow); }
.event-type.permission { color: var(--accent-red); }

.event-detail {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px 0;
}

/* ===== Utilities ===== */
@media (min-width: 500px) {
  .card { margin: 8px auto; max-width: 480px; }
  .header { max-width: 480px; margin: 0 auto; }
}
