/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #F5F5F7;
  --surface:     #FFFFFF;
  --border:      #E5E5EA;
  --text-1:      #1D1D1F;
  --text-2:      #6E6E73;
  --text-3:      #AEAEB2;
  --green:       #34C759;
  --green-light: #D1FAE5;
  --blue:        #007AFF;
  --blue-light:  #DBEAFE;
  --red:         #FF3B30;
  --red-light:   #FEE2E2;
  --gray:        #8E8E93;
  --gray-light:  #F2F2F7;
  --radius:      18px;
  --radius-sm:   12px;
  --nav-h:       82px;
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
}

/* ── Screen system ─────────────────────────────────────────────────────────── */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
#screen-login {
  background: var(--surface);
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  padding-top: calc(40px + var(--safe-top));
}

.login-wrap { width: 100%; max-width: 340px; }

.login-logo {
  text-align: center;
  margin-bottom: 20px;
}
.login-logo img { border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,.12); }

.login-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.login-sub {
  text-align: center;
  color: var(--text-2);
  font-size: 15px;
  margin-bottom: 40px;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

.field-wrap { display: flex; flex-direction: column; gap: 6px; }
.field-wrap label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.field-wrap input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.field-wrap input:focus { border-color: var(--blue); background: var(--surface); }

.form-error {
  font-size: 13px;
  color: var(--red);
  text-align: center;
  padding: 2px 0;
}

/* ── Install prompt ────────────────────────────────────────────────────────── */
#screen-install {
  background: var(--surface);
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
  padding-top: calc(60px + var(--safe-top));
}

.install-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.install-icon { border-radius: 22px; box-shadow: 0 4px 20px rgba(0,0,0,.12); }
.install-wrap h2 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.3px;
}
.install-beta {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  line-height: 1.6;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  width: 100%;
}
.install-beta strong { color: var(--text-1); }

.install-steps { width: 100%; }

.steps-list {
  padding: 0 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}
.steps-list li {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-1);
}
.icon-inline {
  display: inline-block;
  padding: 2px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
}
.install-tip {
  font-size: 13px;
  color: var(--text-2);
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 15px;
  font-family: var(--font);
  padding: 10px;
  cursor: pointer;
  margin-top: 4px;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app-shell {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
#app-shell .screen {
  position: relative;
  flex: 1;
  inset: auto;
  padding-bottom: var(--nav-h);
}
#app-shell .screen.active { display: flex; flex-direction: column; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  padding: 0 20px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.9);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.header-icon {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s;
}
.header-icon:active { background: var(--bg); }

/* ── Screen body ───────────────────────────────────────────────────────────── */
.screen-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
}

/* ── Center states ─────────────────────────────────────────────────────────── */
.center-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 32px;
  text-align: center;
}
.empty-icon { font-size: 44px; line-height: 1; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text-1); }
.empty-sub   { font-size: 14px; color: var(--text-2); }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Post card ─────────────────────────────────────────────────────────────── */
.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0,0,0,.07);
}

.post-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg);
  overflow: hidden;
}
.post-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.post-image-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 13px;
}

.post-meta { padding: 16px 16px 0; }
.post-scheduled {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.post-caption-wrap { position: relative; }
.post-caption {
  width: 100%;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-1);
  font-family: var(--font);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px;
  resize: none;
  background: transparent;
  outline: none;
  transition: border-color .15s, background .15s;
  margin: 0 -10px;
  width: calc(100% + 20px);
}
.post-caption:focus {
  border-color: var(--blue);
  background: var(--bg);
  margin: 0 -10px;
}
.caption-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
  margin-bottom: 2px;
}

.post-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 16px;
}

.review-counter {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
  margin-top: 14px;
}

.action-feedback {
  margin: 0 16px 16px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  font-weight: 500;
}
.action-feedback.success { background: var(--green-light); color: #065F46; }
.action-feedback.error   { background: var(--red-light);   color: #991B1B; }

/* ── History ───────────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
}
.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.history-caption {
  font-size: 14px;
  color: var(--text-1);
  line-height: 1.45;
  flex: 1;
  /* 2-line clamp */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-meta {
  font-size: 12px;
  color: var(--text-3);
}
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
}
.status-posted  { background: var(--green-light); color: #065F46; }
.status-failed  { background: var(--red-light);   color: #991B1B; }
.status-skipped { background: var(--gray-light);  color: var(--gray); }

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 30px; }

.settings-group {
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  width: 100%;
}
.settings-row:last-child { border-bottom: none; }
.settings-btn {
  background: none;
  border: none;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .15s;
}
.settings-btn:active { background: var(--bg); }
.settings-label {
  font-size: 15px;
  color: var(--text-1);
}
.settings-value {
  font-size: 15px;
  color: var(--text-2);
}
.settings-btn.danger .settings-label { color: var(--red); }
.settings-version {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  margin-top: -16px;
}

/* ── Bottom navigation ─────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 6px;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  color: var(--text-3);
  font-size: 10px;
  font-family: var(--font);
  font-weight: 500;
  position: relative;
  transition: color .15s;
}
.nav-item.active { color: var(--blue); }
.nav-icon { width: 24px; height: 24px; }
.nav-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 18px);
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  padding: 12px 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { opacity: 0.8; transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-full { width: 100%; padding: 15px; font-size: 16px; border-radius: var(--radius-sm); }

.btn-primary   { background: var(--blue);  color: white; }
.btn-approve   { background: var(--green); color: white; }
.btn-post-now  { background: var(--blue);  color: white; }
.btn-skip      { background: var(--gray-light); color: var(--text-1); }

.btn-label { display: inline; }
.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
