/* DDK Social — Styles */
:root {
  --primary: #E8A87C;
  --primary-dark: #D4956A;
  --accent: #5C3D2E;
  --bg: #FFF9F2;
  --card: #FFFFFF;
  --text: #3D2B1F;
  --text2: #8B7355;
  --border: #E8DDD0;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(92,61,46,.08);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100dvh; overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; border: none; outline: none; }
img { max-width: 100%; display: block; }

/* ---- Demo bar ---- */
.demo-bar {
  background: var(--warn); color: #fff; text-align: center;
  padding: 6px 16px; font-size: .82rem; font-weight: 600;
  position: sticky; top: 0; z-index: 200;
}

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; padding: 10px 24px;
  border-radius: 24px; font-size: .88rem; z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); transition: opacity .3s;
}
#toast[hidden] { display: block; opacity: 0; pointer-events: none; }
#toast.bad { background: var(--danger); }

/* ---- Top Nav ---- */
.top-nav {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--accent); color: #fff;
  position: sticky; top: 0; z-index: 100;
}
.demo-bar + #app .top-nav, .demo-bar ~ #app .top-nav { top: 32px; }
.nav-btn { background: none; color: #fff; padding: 6px; cursor: pointer; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-title { flex: 1; font-weight: 700; font-size: 1.05rem; }
.nav-user { font-size: .82rem; opacity: .85; }
.nav-menu {
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; color: var(--text); padding: 8px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); display: none; z-index: 101;
}
.nav-menu.open { display: block; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; color: var(--text); font-size: .95rem;
}
.nav-item:active { background: var(--bg); }
.nav-item svg { width: 18px; height: 18px; color: var(--text2); }
.nav-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---- Login ---- */
.login {
  max-width: 380px; margin: 60px auto; padding: 32px 24px; text-align: center;
}
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.logo-icon { width: 40px; height: 40px; color: var(--primary); }
.logo h1 { font-size: 1.5rem; color: var(--accent); }
.subtitle { color: var(--text2); margin-bottom: 28px; font-size: .9rem; }
.login input {
  width: 100%; padding: 14px 16px; border: 1.5px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px; font-size: 1rem;
  background: #fff;
}
.login input:focus { border-color: var(--primary); }
.login .error { color: var(--danger); font-size: .85rem; min-height: 22px; margin-bottom: 8px; }
.demo-hint { margin-top: 20px; font-size: .78rem; color: var(--text2); line-height: 1.5; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px; border-radius: var(--radius); font-weight: 600;
  font-size: .92rem; cursor: pointer; background: var(--card);
  color: var(--text); border: 1.5px solid var(--border);
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: .82rem; }
.sm-icon { width: 16px; height: 16px; }
.big-icon { width: 48px; height: 48px; color: var(--text2); }

/* ---- Screen ---- */
.screen { padding: 16px; max-width: 600px; margin: 0 auto; padding-bottom: 80px; }
.loading { text-align: center; padding: 40px; color: var(--text2); }
.empty { text-align: center; padding: 20px; color: var(--text2); font-size: .88rem; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--text2); }
.empty-state p { margin: 12px 0 20px; }

/* ---- Date bar ---- */
.date-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding: 10px 14px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.date-bar span { font-weight: 600; font-size: .95rem; }

/* ---- Branch card ---- */
.branch-card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.branch-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.branch-header svg { width: 18px; height: 18px; color: var(--primary); }
.branch-actions { margin-top: 12px; text-align: right; }

/* ---- Flavour chips ---- */
.flavour-grid {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.flavour-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); padding: 8px 14px; border-radius: 20px;
  font-size: .85rem; border: 1px solid var(--border);
}
.flavour-name { font-weight: 600; }
.flavour-tubs { color: var(--text2); font-size: .78rem; }

/* ---- Compose ---- */
.compose-header { margin-bottom: 16px; }
.compose-header h2 { margin-top: 8px; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text2); font-size: .88rem;
}
.compose-section {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.compose-section h3 { font-size: .95rem; margin-bottom: 12px; }
.compose-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

/* Flavour select toggles */
.flavour-select { display: flex; flex-wrap: wrap; gap: 8px; }
.flavour-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 20px; font-size: .85rem;
  background: var(--bg); border: 1.5px solid var(--border); cursor: pointer;
  transition: all .15s;
}
.flavour-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.flavour-toggle input { display: none; }

/* ---- Template grid (selection) ---- */
.template-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.template-card {
  flex: 1 1 140px; min-width: 130px; padding: 14px; border-radius: var(--radius);
  border: 2px solid transparent; cursor: pointer; transition: all .15s;
}
.template-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.template-name { font-weight: 700; font-size: .85rem; margin-bottom: 6px; }
.template-preview-flavours { font-size: .72rem; opacity: .8; }
.template-preview-flavours span { display: inline-block; margin-right: 4px; }

/* ---- Caption ---- */
.caption-input {
  width: 100%; padding: 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; resize: vertical;
  background: var(--bg); line-height: 1.5;
}
.caption-input:focus { border-color: var(--primary); }

/* ---- Preview ---- */
.preview-wrapper { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.preview-canvas {
  aspect-ratio: 1; padding: 24px; display: flex; flex-direction: column;
  border: 2px solid var(--border); border-radius: var(--radius);
}
.preview-empty { text-align: center; color: var(--text2); padding: 32px; font-size: .88rem; }
.preview-header { text-align: center; margin-bottom: 16px; }
.preview-logo { font-size: 1.1rem; font-weight: 700; }
.preview-store { font-size: .82rem; opacity: .8; margin-top: 2px; }
.preview-flavours { flex: 1; padding: 8px 0; }
.preview-flavours.grid-layout { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.preview-flavour-item {
  display: flex; align-items: center; gap: 8px;
  font-size: .88rem; font-weight: 600; padding: 4px 0;
}
.preview-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.preview-flavour-row {
  display: flex; align-items: baseline; gap: 8px;
  font-size: .88rem; padding: 3px 0;
}
.preview-num { font-weight: 700; min-width: 20px; }
.preview-caption {
  font-size: .78rem; text-align: center; padding: 8px 0;
  opacity: .85; font-style: italic; line-height: 1.4;
}
.preview-footer {
  font-size: .7rem; text-align: center; padding-top: 8px;
  border-top: 1px solid currentColor; opacity: .7;
}

/* ---- Template list ---- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h2 { font-size: 1.1rem; }
.template-list { display: flex; flex-direction: column; gap: 10px; }
.template-list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.template-info strong { display: block; margin-bottom: 4px; }
.template-meta { font-size: .78rem; opacity: .7; }

/* ---- Template form ---- */
.template-form { display: flex; flex-direction: column; gap: 14px; }
.form-field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text2); }
.form-field input, .form-field select {
  width: 100%; padding: 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius); background: #fff; font-size: .92rem;
}
.form-field input[type="color"] { height: 44px; padding: 4px 8px; cursor: pointer; }
.form-field input:focus, .form-field select:focus { border-color: var(--primary); }

/* ---- Posts list ---- */
.posts-list { display: flex; flex-direction: column; gap: 10px; }
.post-card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: flex-start; gap: 12px;
  transition: transform .1s;
}
.post-card:active { transform: scale(.98); }
.post-status {
  padding: 4px 10px; border-radius: 12px; color: #fff;
  font-size: .72rem; font-weight: 700; white-space: nowrap; flex-shrink: 0;
}
.post-info { flex: 1; min-width: 0; }
.post-info strong { font-size: .92rem; }
.post-meta { font-size: .78rem; color: var(--text2); margin-top: 2px; }
.post-date { font-size: .72rem; color: var(--text2); margin-top: 2px; }
.post-caption-preview {
  font-size: .78rem; color: var(--text2); font-style: italic;
  margin-top: 6px; line-height: 1.4;
}

/* ---- Post detail ---- */
.post-detail { padding-top: 8px; }
.post-detail-status {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.status-badge {
  display: inline-block; padding: 5px 14px; border-radius: 14px;
  color: #fff; font-size: .8rem; font-weight: 700;
}
.status-badge.draft { background: #94a3b8; }
.status-badge.pending { background: #f59e0b; }
.status-badge.approved { background: #22c55e; }
.status-badge.rejected { background: #ef4444; }
.status-badge.posted { background: #8b5cf6; }
.post-detail-date { font-size: .82rem; color: var(--text2); }
.post-detail h2 { margin-bottom: 16px; }
.post-detail-flavours { margin-bottom: 16px; }
.post-detail-flavours h3 { margin-bottom: 10px; font-size: .95rem; }
.post-detail-caption { margin-bottom: 16px; }
.post-detail-caption h3 { margin-bottom: 8px; font-size: .95rem; }
.post-detail-caption p { line-height: 1.5; color: var(--text2); }
.post-detail-actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.approval-btns { display: flex; flex-direction: column; gap: 8px; }
.hint { font-size: .78rem; color: var(--text2); text-align: center; margin: 6px 0; }

/* ---- Safe area ---- */
@supports (padding: env(safe-area-inset-bottom)) {
  .screen { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* reject note, team screen */
.reject-note { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 10px 12px; margin: 8px 0 12px; font-size: 14px; }
.team-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.team-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border-radius: 12px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.team-row select { border: 1px solid #ddd; border-radius: 8px; padding: 8px; background: #fff; max-width: 48%; }
.team-info { min-width: 0; }
.post-detail-caption textarea { width: 100%; }

/* ---- Keypad login (same look and flow as DDK Staff) ---- */
.keypad-login {
  --k-bg: #f2f5f1; --k-surface: #fff; --k-ink: #17201b; --k-muted: #56645c; --k-line: #d5ddd6;
  --k-accent: #25553f; --k-accent-ink: #fff; --k-accent-soft: #dcebe1; --k-bad: #b42318; --k-bad-soft: #fbe0dc;
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 22px; max-width: 420px; margin: 0 auto; text-align: left;
  padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  color: var(--k-ink); font-family: "Anuphan", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, sans-serif; font-size: 17px; line-height: 1.45;
}
body:has(.keypad-login) { background: var(--k-bg, #f2f5f1); }
@media (prefers-color-scheme: dark) {
  .keypad-login { --k-bg: #101512; --k-surface: #18201b; --k-ink: #e9efe9; --k-muted: #9fb0a5; --k-line: #2d3a32;
    --k-accent: #7cc39b; --k-accent-ink: #0d1a13; --k-accent-soft: #1f3529; --k-bad: #ff8a7a; --k-bad-soft: #3d1a16; }
  body:has(.keypad-login) { background: #101512; }
}
.keypad-login h1 { font-size: 1.5rem; margin: 0; }
.keypad-login .muted { color: var(--k-muted); }
.keypad-login .small { font-size: .9rem; }
.keypad-login .center { text-align: center; margin: 0; }
.keypad-login .brand { display: flex; align-items: center; gap: 12px; }
.keypad-login .brand img { width: 52px; height: 52px; border-radius: 14px; object-fit: cover; }
.keypad-login .brand .name { font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.keypad-login .phone-display { font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.9rem; text-align: center; letter-spacing: .06em; min-height: 48px; }
.keypad-login .pin-dots { display: flex; justify-content: center; gap: 14px; padding: 8px 0; }
.keypad-login .pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--k-accent); }
.keypad-login .pin-dots i.on { background: var(--k-accent); }
.keypad-login .keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad-login .keypad button { height: 64px; border-radius: 16px; border: 1px solid var(--k-line); background: var(--k-surface); color: var(--k-ink); font-size: 1.6rem; font-weight: 600; cursor: pointer; }
.keypad-login .keypad button:active { background: var(--k-accent-soft); }
.keypad-login .keypad button.fn { font-size: 1rem; background: transparent; border-color: transparent; }
.keypad-login .btn { min-height: 56px; border-radius: 14px; border: 1px solid var(--k-line); background: var(--k-surface); color: var(--k-ink); font-weight: 600; font-size: 1rem; box-shadow: none; }
.keypad-login .btn.primary { background: var(--k-accent); color: var(--k-accent-ink); border-color: var(--k-accent); }
.keypad-login .btn:disabled { opacity: .55; }
.keypad-login .banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: .95rem; background: var(--k-bad-soft); color: var(--k-bad); }
.keypad-login .banner svg { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.keypad-login .chip { align-self: center; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 40px; border-radius: 999px;
  background: var(--k-surface); color: var(--k-ink); border: 1px solid var(--k-line); font-size: .9rem; cursor: pointer; }
.keypad-login .chip svg { width: 16px; height: 16px; }
.keypad-login .chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.keypad-login .card { background: var(--k-surface); border: 1px solid var(--k-line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.keypad-login .demo-card .chip { align-self: auto; }
