:root {
  /* TikTok-style dark + white accent */
  --bg: #000000;
  --bg-window: #1c1c1e;
  --bg-elevated: #2c2c2e;
  --fill: rgba(120, 120, 128, 0.24);
  --fill-secondary: rgba(120, 120, 128, 0.16);
  --sidebar: rgba(28, 28, 30, 0.72);
  --sidebar-solid: #1c1c1e;
  --separator: rgba(84, 84, 88, 0.65);
  --label: #ffffff;
  --secondary-label: rgba(235, 235, 245, 0.6);
  --tertiary-label: rgba(235, 235, 245, 0.3);
  --accent: #ffffff;
  --accent-on: #000000;
  --accent-soft: rgba(255, 255, 255, 0.14);
  --user-bubble: #ffffff;
  --user-bubble-text: #000000;
  --assistant-bubble: #3a3a3c;
  --danger: #ff453a;
  --ok: #30d158;
  --input-bg: rgba(118, 118, 128, 0.24);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-bubble: 18px;
  --r-pill: 980px;
  --sidebar-width: 280px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", sans-serif;
  --shadow-sheet: 0 8px 40px rgba(0, 0, 0, 0.45);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }

/* —— Controls —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--fill);
  color: var(--label);
  font-size: 15px;
  font-weight: 510;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--fill-secondary); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-on);
}
.btn-primary:hover {
  filter: none;
  background: #f2f2f2;
  color: var(--accent-on);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: rgba(255, 69, 58, 0.12); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 7px; }
.btn-plain {
  background: transparent;
  color: var(--accent);
  font-weight: 510;
}

.input, .select, .textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--input-bg);
  border: none;
  border-radius: var(--r-sm);
  color: var(--label);
  font-size: 15px;
  outline: none;
  transition: box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select option { background: var(--bg-elevated); }

.label {
  display: block;
  font-size: 13px;
  color: var(--secondary-label);
  margin-bottom: 6px;
  font-weight: 510;
}
.form-group { margin-bottom: 14px; }
.password-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.password-wrap .input { flex: 1; }

.toast {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(44, 44, 46, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid var(--separator);
  color: var(--label);
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1), transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow-sheet);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ok { color: var(--ok); }

/* —— Login (zMessage) —— */
.login-page {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255, 255, 255, 0.12), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(28, 28, 30, 0.78);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border: 0.5px solid var(--separator);
  border-radius: 22px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow-sheet);
  animation: cardIn 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
  text-align: center;
}
.login-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-on);
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.12);
}
.login-card h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 4px;
}
.login-card .sub {
  font-size: 14px;
  color: var(--secondary-label);
  line-height: 1.4;
}
.login-card .btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border-radius: var(--r-pill);
  font-size: 17px;
  font-weight: 600;
}

/* —— App shell —— */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-right: 0.5px solid var(--separator);
  display: flex;
  flex-direction: column;
}
.sidebar-header { padding: 14px 12px 8px; }
.sidebar-header-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sidebar-title { font-size: 17px; font-weight: 650; }
.sidebar-footer {
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--separator);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-footer .settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  color: var(--label);
  font-size: 15px;
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s, transform 0.12s;
}
.sidebar-footer .settings-row:active { transform: scale(0.98); background: var(--fill); }
.sidebar-footer .settings-row .chevron {
  color: var(--tertiary-label);
  font-size: 18px;
  font-weight: 300;
}
.sidebar-footer .settings-row.danger { color: var(--danger); }
.sidebar-user {
  font-size: 12px;
  color: var(--secondary-label);
  padding: 4px 12px 8px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-window);
}

.usage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 12px;
  color: var(--secondary-label);
  flex-shrink: 0;
  background: rgba(28, 28, 30, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.usage-bar strong { color: var(--label); font-weight: 560; }

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  -webkit-overflow-scrolling: touch;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  color: var(--secondary-label);
  margin-bottom: 2px;
  animation: listIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: background 0.12s, transform 0.12s, color 0.12s;
}
.session-item:nth-child(1) { animation-delay: 0.02s; }
.session-item:nth-child(2) { animation-delay: 0.04s; }
.session-item:nth-child(3) { animation-delay: 0.06s; }
.session-item:nth-child(4) { animation-delay: 0.08s; }
.session-item:nth-child(5) { animation-delay: 0.1s; }
.session-item:hover { background: var(--fill-secondary); color: var(--label); }
.session-item:active { transform: scale(0.98); }
.session-item.active {
  background: var(--accent-soft);
  color: var(--label);
}
.session-item .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 510;
}
.session-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 4px;
}
.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: var(--fill);
  color: var(--secondary-label);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  opacity: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s, background 0.12s, color 0.12s, transform 0.12s;
}
.icon-btn svg {
  display: block;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.session-item:hover .icon-btn,
.session-item:focus-within .icon-btn { opacity: 1; }
.icon-btn:hover {
  background: var(--fill-secondary);
  color: var(--label);
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn.btn-del:hover {
  background: rgba(255, 69, 58, 0.18);
  color: var(--danger, #ff453a);
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
  -webkit-overflow-scrolling: touch;
}
.messages-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48vh;
  color: var(--secondary-label);
  text-align: center;
  gap: 8px;
  animation: cardIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.empty-state h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--label);
  letter-spacing: -0.5px;
}
.empty-state p { font-size: 15px; max-width: 280px; line-height: 1.45; }

/* iMessage bubbles */
.message {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: bubbleIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.message.user {
  align-self: flex-end;
  margin-left: auto;
  align-items: flex-end;
}
.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}
.message-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--tertiary-label);
  padding: 0 4px;
}
.message.user .message-header { flex-direction: row-reverse; }
.message-role { font-weight: 510; color: var(--secondary-label); }
.message-model {
  padding: 1px 7px;
  background: var(--fill);
  color: var(--secondary-label);
  border-radius: var(--r-pill);
  font-size: 10px;
}
.message-body {
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
  padding: 9px 14px;
  border-radius: var(--r-bubble);
}
.message.user .message-body {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}
.message.assistant .message-body {
  background: var(--assistant-bubble);
  color: var(--label);
  border-bottom-left-radius: 5px;
}
.message-body.streaming { white-space: pre-wrap; }
.cursor {
  color: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.md-content h1, .md-content h2, .md-content h3 {
  margin: 0.85em 0 0.4em;
  font-weight: 650;
}
.md-content p { margin: 0.45em 0; }
.md-content ul, .md-content ol { margin: 0.45em 0; padding-left: 1.35em; }
.md-content code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: "SF Mono", Menlo, Monaco, monospace;
}
.md-content pre {
  margin: 10px 0;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000 !important;
}
.md-content pre code {
  background: none;
  padding: 14px;
  display: block;
  overflow-x: auto;
  font-size: 13px;
}
.md-content table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.md-content th, .md-content td {
  border: 0.5px solid var(--separator);
  padding: 8px 10px;
  text-align: left;
}
.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 10px 0;
  color: var(--secondary-label);
}
.md-content a { color: var(--accent); }

.input-area {
  padding: 10px 20px 18px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.input-wrapper {
  background: var(--bg-elevated);
  border: 0.5px solid var(--separator);
  border-radius: 22px;
  padding: 10px 12px 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.input-wrapper:focus-within {
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 4px 24px rgba(0, 0, 0, 0.25);
}
.input-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.model-select {
  -webkit-appearance: none;
  appearance: none;
  width: auto;
  max-width: min(240px, 100%);
  min-height: 28px;
  padding: 5px 28px 5px 12px;
  background-color: var(--fill);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1.5 1.75L6 6.25L10.5 1.75' stroke='%238E8E93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 11px 7px;
  border: none;
  border-radius: var(--r-pill);
  color: var(--label);
  font-size: 13px;
  font-weight: 510;
  line-height: 1.2;
  cursor: pointer;
}
.model-select:focus { outline: none; }
.model-picker-btn {
  display: none;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 32px;
  padding: 6px 12px;
  background: var(--fill);
  border: none;
  border-radius: var(--r-pill);
  color: var(--label);
  font-size: 14px;
  font-weight: 510;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s, opacity 0.15s;
}
.model-picker-btn:active { transform: scale(0.97); opacity: 0.85; }
.model-picker-btn #model-picker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-picker-chevron {
  flex-shrink: 0;
  color: var(--secondary-label);
  margin-top: 1px;
}

/* Bottom sheet — model picker (mobile) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.28s;
}
.sheet-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.sheet-backdrop[hidden] { display: none !important; }
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  max-height: min(58dvh, 420px);
  background: var(--bg-elevated);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-sheet);
  padding: 0 0 max(12px, env(safe-area-inset-bottom));
  transform: translateY(105%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.38s;
}
.bottom-sheet.open {
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}
.bottom-sheet[hidden] { display: none !important; }
.sheet-grabber {
  width: 36px;
  height: 5px;
  margin: 8px auto 4px;
  border-radius: 999px;
  background: var(--fill-strong, rgba(255, 255, 255, 0.28));
  flex-shrink: 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 12px;
  flex-shrink: 0;
}
.sheet-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.sheet-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 8px;
  overscroll-behavior: contain;
}
.sheet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  margin-bottom: 6px;
  border: none;
  border-radius: 12px;
  background: var(--fill);
  color: var(--label);
  font-size: 16px;
  font-weight: 510;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.12s;
}
.sheet-option:active { transform: scale(0.985); }
.sheet-option.selected {
  background: var(--accent-soft);
  color: var(--label);
}
.sheet-option .check {
  width: 22px;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  visibility: hidden;
}
.sheet-option.selected .check { visibility: visible; }
.sheet-option .opt-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-option.empty {
  justify-content: center;
  color: var(--secondary-label);
  pointer-events: none;
}
body.sheet-open { overflow: hidden; }

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--label);
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  max-height: 160px;
  min-height: 24px;
  padding: 5px 0;
  outline: none;
}
#message-input::placeholder { color: var(--tertiary-label); }
.btn-send {
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-on);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  transition: transform 0.12s, opacity 0.15s, background 0.15s;
}
.btn-send svg {
  display: block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.btn-send:hover { background: #f2f2f2; }
.btn-send:active { transform: scale(0.92); }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
.input-hint {
  font-size: 11px;
  color: var(--tertiary-label);
  margin-top: 8px;
  text-align: center;
}

/* —— Admin —— */
.admin-page {
  min-height: 100%;
  min-height: 100dvh;
  padding: 28px 24px 40px;
  max-width: 980px;
  margin: 0 auto;
  background: var(--bg);
}
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.admin-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.4px;
}
.admin-header .sub {
  font-size: 13px;
  color: var(--secondary-label);
  margin-top: 4px;
}
.admin-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs, .segmented {
  display: flex;
  gap: 0;
  margin-bottom: 18px;
  padding: 3px;
  background: var(--fill);
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
}
.tab {
  padding: 7px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--secondary-label);
  cursor: pointer;
  font-size: 13px;
  font-weight: 560;
  transition: background 0.15s, color 0.15s, transform 0.12s;
  white-space: nowrap;
}
.tab:active { transform: scale(0.97); }
.tab.active {
  background: var(--bg-elevated);
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.panel {
  background: var(--bg-window);
  border: 0.5px solid var(--separator);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h2 {
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 12px;
  color: var(--secondary-label);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: 12px 8px;
  border-bottom: 0.5px solid var(--separator);
  vertical-align: middle;
}
.table th {
  color: var(--secondary-label);
  font-weight: 560;
  font-size: 12px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 560;
}
.badge-ok { background: rgba(48, 209, 88, 0.18); color: var(--ok); }
.badge-off { background: rgba(255, 69, 58, 0.18); color: var(--danger); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status-box {
  padding: 14px;
  border-radius: var(--r-md);
  background: var(--fill-secondary);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--secondary-label);
}
.status-box.ok { color: var(--ok); }
.status-box.fail { color: var(--danger); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Mobile cards for admin lists */
.card-list { display: none; }
.admin-card {
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
  border: 0.5px solid var(--separator);
  animation: listIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.admin-card .card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}
.admin-card .card-meta {
  font-size: 13px;
  color: var(--secondary-label);
  margin-bottom: 10px;
  line-height: 1.45;
}
.admin-card .row-actions { flex-direction: column; }
.admin-card .row-actions .btn { width: 100%; min-height: 40px; }

.mobile-topbar { display: none; }
.mobile-only { display: none !important; }
.desktop-only { display: flex; }
.input-hint.desktop-only { display: block; }
.sidebar-backdrop { display: none; }
.icon-hit {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, background 0.12s;
}
.icon-hit:active { transform: scale(0.92); background: var(--fill); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes listIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
  .table-wrap-desktop { display: none !important; }
  .card-list { display: block; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    padding-top: max(4px, env(safe-area-inset-top));
    border-bottom: 0.5px solid var(--separator);
    flex-shrink: 0;
    background: rgba(28, 28, 30, 0.82);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
  }
  .mobile-topbar-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-align: center;
  }
  .mobile-topbar-title strong {
    font-size: 16px;
    font-weight: 650;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-topbar-title span {
    font-size: 11px;
    color: var(--secondary-label);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
    opacity: 1;
    transition: opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .sidebar-backdrop[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: min(88vw, 320px);
    min-width: 0;
    background: var(--sidebar-solid);
    transform: translateX(-105%);
    transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: var(--shadow-sheet);
    backdrop-filter: none;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-header-row { display: flex; }
  .sidebar-footer .settings-row {
    background: var(--bg-elevated);
    margin-bottom: 6px;
  }
  .session-item { min-height: 52px; padding: 10px 10px 10px 14px; gap: 8px; }
  .session-item .icon-btn {
    opacity: 1;
    width: 36px;
    height: 36px;
  }
  .session-item .icon-btn svg {
    width: 16px;
    height: 16px;
  }
  .session-actions { gap: 6px; }

  .messages-container { padding: 0 12px; }
  .message { max-width: 88%; }
  .input-area {
    padding: 8px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .model-select.desktop-only { display: none !important; }
  .model-picker-btn.mobile-only { display: inline-flex !important; }
  #message-input { font-size: 16px; }
  .btn-send { width: 36px; height: 36px; }

  .admin-page {
    padding: 16px 14px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .admin-header { flex-direction: column; align-items: stretch; }
  .admin-header h1 { font-size: 26px; }
  .admin-toolbar { width: 100%; }
  .admin-toolbar .btn { flex: 1; min-height: 44px; }
  .tabs, .segmented {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab { flex: 1; text-align: center; min-height: 36px; }
  .panel { padding: 14px; border-radius: 14px; }
  .row-actions { flex-direction: column; }
  .row-actions .btn { width: 100%; min-height: 40px; }
}

/* —— Apple Confirm / Prompt —— */
body.apple-dialog-open { overflow: hidden; }
#apple-dialog-host { position: relative; z-index: 200; }
.apple-dialog-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.apple-dialog-root.open {
  opacity: 1;
  pointer-events: auto;
}
.apple-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.apple-dialog-panel {
  position: relative;
  z-index: 1;
  width: min(270px, 100%);
  background: rgba(44, 44, 46, 0.94);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sheet);
  transform: scale(1.04);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.apple-dialog-root.open .apple-dialog-panel { transform: scale(1); }
.apple-dialog-grabber,
.apple-dialog-sheet-cancel { display: none; }
.apple-dialog-body {
  padding: 20px 16px 14px;
  text-align: center;
}
.apple-dialog-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--label);
}
.apple-dialog-message {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--secondary-label);
}
.apple-dialog-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  text-align: left;
}
.apple-dialog-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--fill);
  color: var(--label);
  font-size: 16px;
  outline: none;
}
.apple-dialog-input:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.apple-dialog-toggle {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 510;
  cursor: pointer;
  padding: 8px 4px;
}
.apple-dialog-actions {
  display: flex;
  border-top: 0.5px solid var(--separator);
}
.apple-dialog-actions .apple-dialog-btn {
  flex: 1;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
  padding: 11px 8px;
  -webkit-tap-highlight-color: transparent;
}
.apple-dialog-actions .apple-dialog-btn + .apple-dialog-btn {
  border-left: 0.5px solid var(--separator);
}
.apple-dialog-actions .apple-dialog-btn.primary { font-weight: 600; }
.apple-dialog-actions .apple-dialog-btn.danger { color: var(--danger); font-weight: 600; }
.apple-dialog-actions .apple-dialog-btn:active { background: var(--fill-secondary); }

/* Mobile Action Sheet */
.apple-dialog-root.is-sheet {
  align-items: flex-end;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
}
.apple-dialog-root.is-sheet .apple-dialog-panel {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border-radius: 0;
  overflow: visible;
  transform: translateY(110%);
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
.apple-dialog-root.is-sheet.open .apple-dialog-panel { transform: translateY(0); }
.apple-dialog-root.is-sheet .apple-dialog-grabber {
  display: block;
  width: 36px;
  height: 5px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}
.apple-dialog-root.is-sheet .apple-dialog-body {
  background: var(--bg-elevated);
  border-radius: 14px 14px 0 0;
  padding: 8px 16px 16px;
  text-align: left;
}
.apple-dialog-root.is-sheet .apple-dialog-title { font-size: 13px; color: var(--secondary-label); font-weight: 510; text-align: center; }
.apple-dialog-root.is-sheet .apple-dialog-message { text-align: center; margin-top: 4px; }
.apple-dialog-root.is-sheet .apple-dialog-actions {
  flex-direction: column;
  border-top: none;
  background: var(--bg-elevated);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
}
.apple-dialog-root.is-sheet .apple-dialog-actions .apple-dialog-btn {
  width: 100%;
  min-height: 56px;
  border-left: none !important;
  border-top: 0.5px solid var(--separator);
  font-size: 20px;
  font-weight: 400;
}
.apple-dialog-root.is-sheet .apple-dialog-actions .apple-dialog-btn[data-action="cancel"] {
  display: none; /* 取消放到下方独立块 */
}
.apple-dialog-root.is-sheet .apple-dialog-sheet-cancel {
  display: block;
  margin-top: 8px;
  background: var(--bg-elevated);
  border-radius: 14px;
  overflow: hidden;
}
.apple-dialog-root.is-sheet .apple-dialog-sheet-cancel .apple-dialog-btn {
  width: 100%;
  min-height: 56px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
}
.apple-dialog-root.is-sheet .apple-dialog-sheet-cancel .apple-dialog-btn:active {
  background: var(--fill-secondary);
}
.apple-dialog-root.is-alert .apple-dialog-actions .apple-dialog-btn[data-action="cancel"] {
  font-weight: 400;
}

