:root {
  --primary: #FF2D55;
  --primary-dark: #C8204A;
  --text: #32323A;
  --text-muted: #8E8E93;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --border: #E5E5EA;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ─── Header ─── */
.header {
  position: sticky; top:0; z-index:100;
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(255,45,85,0.3);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.logo { font-weight:700; font-size:18px; }
.nav { display:flex; gap:4px; }
.nav-btn {
  background: transparent; border:none; color:rgba(255,255,255,.7);
  padding: 8px 16px; border-radius:8px; cursor:pointer;
  font: 500 14px/1 'Inter', sans-serif;
  transition: all .2s;
}
.nav-btn:hover { color:white; background:rgba(255,255,255,.15); }
.nav-btn.active { color:white; background:rgba(255,255,255,.2); }

/* Mobile bottom tab bar */
.mobile-nav {
  display: none;
}

/* ─── Main ─── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.tab-content { display:none; }
.tab-content.active { display:block; animation: fadeIn .3s; }
@keyframes fadeIn { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

/* ─── Cards ─── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 { font-size:20px; margin-bottom:20px; }

/* ─── Forms ─── */
.form-group { margin-bottom:16px; }
.form-group label {
  display:block; font-size:13px; font-weight:600;
  color: var(--text-muted); margin-bottom:6px; text-transform:uppercase; letter-spacing:.5px;
}
.form-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; }

input[type="text"], input[type="date"], select, textarea {
  width:100%; padding:10px 14px; border:1px solid var(--border);
  border-radius:8px; font:400 15px/1.4 'Inter', sans-serif;
  transition: border-color .2s;
  background: white; color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline:none; border-color:var(--primary);
  box-shadow: 0 0 0 3px rgba(255,45,85,.12);
}

/* ─── Buttons ─── */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding:10px 20px; border:none; border-radius:8px;
  font: 600 14px/1 'Inter', sans-serif;
  cursor:pointer; transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform:scale(.97); }
.btn-primary { background:var(--primary); color:white; }
.btn-primary:hover { background:var(--primary-dark); }
.btn-outline { background:transparent; border:1px solid var(--border); color:var(--text); }
.btn-outline:hover { border-color:var(--primary); color:var(--primary); }
.btn-sm { padding:6px 14px; font-size:13px; }
.btn-lg { width:100%; padding:14px; font-size:16px; margin-top:8px; }
.btn-danger { background:#FF3B30; color:white; }
.btn-danger:hover { background:#D62C23; }
.btn-copy {
  position:absolute; top:8px; right:8px;
  background:var(--primary); color:white;
  padding:6px 14px; border-radius:6px; border:none;
  font:600 12px/1 'Inter',sans-serif; cursor:pointer;
  opacity:.9; transition: all .2s;
}
.btn-copy:hover { opacity:1; }

/* ─── Categories ─── */
.cats-header {
  display:flex; justify-content:space-between; align-items:center;
  flex-wrap:wrap; gap:8px; margin-bottom:8px;
}
.cats-actions { display:flex; gap:6px; flex-wrap:wrap; }

.categories-list { display:flex; flex-direction:column; gap:12px; }

.category-block {
  border:1px solid var(--border); border-radius:10px; padding:16px;
  background: #FAFAFA; transition: box-shadow .2s;
}
.category-block:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.category-block.dragging { opacity:.5; }

.cat-header {
  display:flex; align-items:center; gap:8px; margin-bottom:10px;
}
.cat-drag {
  cursor:grab; color:var(--text-muted); font-size:18px;
  padding:2px 4px; user-select:none;
  touch-action: none;
  min-width:24px; min-height:24px;
  display:flex; align-items:center; justify-content:center;
}
.cat-drag:active { cursor:grabbing; }
.cat-emoji-input {
  width:48px !important; text-align:center; font-size:20px; padding:6px !important;
}
.cat-name-input { flex:1; min-width:0; }
.cat-remove {
  background:none; border:none; color:var(--text-muted); font-size:20px;
  cursor:pointer; padding:4px 8px; border-radius:6px; transition: all .2s;
  min-width:32px; min-height:32px;
  display:flex; align-items:center; justify-content:center;
}
.cat-remove:hover { color:#FF3B30; background:rgba(255,59,48,.1); }

.dishes-list { display:flex; flex-direction:column; gap:6px; padding-left:28px; }
.dish-row {
  display:flex; gap:8px; align-items:center;
}
.dish-row input { flex:1; padding:8px 12px; font-size:14px; min-width:0; }
.dish-remove {
  background:none; border:none; color:var(--text-muted); font-size:16px;
  cursor:pointer; padding:2px 6px; border-radius:4px;
  min-width:28px; min-height:28px;
  display:flex; align-items:center; justify-content:center;
}
.dish-remove:hover { color:#FF3B30; }
.btn-add-dish {
  background:none; border:1px dashed var(--border); color:var(--text-muted);
  padding:6px 12px; border-radius:6px; font-size:13px; cursor:pointer;
  margin-left:28px; margin-top:6px; transition: all .2s;
}
.btn-add-dish:hover { border-color:var(--primary); color:var(--primary); }

/* ─── Results ─── */
.results { margin-top:24px; }
.results h2 { margin-bottom:20px; }
.results-grid {
  display:grid; grid-template-columns:1fr 1fr; gap:24px;
}
.result-col h3 { margin-bottom:12px; font-size:16px; }

.result-image-wrap {
  background:#F5F5F5; border-radius:10px; padding:12px;
  margin-bottom:12px; text-align:center;
}
.result-image-wrap img { max-width:100%; border-radius:6px; }

.text-tabs { display:flex; gap:4px; margin-bottom:12px; flex-wrap:wrap; }
.text-tab {
  padding:6px 14px; border:1px solid var(--border); border-radius:6px;
  background:white; cursor:pointer; font:500 13px/1 'Inter',sans-serif;
  transition: all .2s;
}
.text-tab:hover { border-color:var(--primary); }
.text-tab.active { background:var(--primary); color:white; border-color:var(--primary); }

.text-output-wrap { position:relative; }
.text-output {
  background:#1E1E2E; color:#CDD6F4; padding:20px;
  border-radius:10px; font:14px/1.6 'Courier New', monospace;
  white-space:pre-wrap; word-break:break-word;
  max-height:500px; overflow-y:auto;
}
.text-preview { max-height:200px; font-size:13px; }

/* ─── HTML Preview ─── */
.html-preview {
  border:1px solid var(--border); border-radius:10px;
  padding:24px; background:white;
}
.hp-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding:24px; border-radius:10px; text-align:center; color:white; margin-bottom:20px;
}
.hp-header h2 { font-size:24px; margin:0; }
.hp-date { color:var(--text-muted); font-size:14px; margin-bottom:16px; }
.hp-category {
  display:inline-block; background:var(--primary); color:white;
  padding:4px 14px; border-radius:6px; font-weight:600; font-size:14px;
  margin-bottom:8px;
}
.hp-dish {
  padding:6px 0 6px 20px; font-size:15px; position:relative;
}
.hp-dish::before {
  content:''; position:absolute; left:4px; top:50%; transform:translateY(-50%);
  width:8px; height:8px; border-radius:50%; background:var(--primary);
}
.hp-section { margin-bottom:16px; }
.hp-footer {
  border-top:1px solid var(--border); padding-top:12px; margin-top:16px;
  text-align:center; color:var(--text-muted); font-size:13px;
}

/* ─── History ─── */
.history-list { display:flex; flex-direction:column; gap:12px; }
.history-item {
  display:flex; align-items:center; gap:16px;
  padding:12px; border:1px solid var(--border); border-radius:10px;
  transition: box-shadow .2s;
}
.history-item:hover { box-shadow: var(--shadow); }
.history-thumb {
  width:80px; height:80px; border-radius:8px; object-fit:cover;
  background:#F5F5F5; flex-shrink:0;
}
.history-info { flex:1; min-width:0; }
.history-info .h-title { font-weight:600; font-size:15px; }
.history-info .h-dates { font-size:13px; color:var(--text-muted); }
.history-info .h-created { font-size:12px; color:var(--text-muted); }
.history-actions { display:flex; gap:6px; flex-wrap:wrap; }

/* ─── Settings extras ─── */
.color-grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.color-input-wrap { display:flex; gap:8px; align-items:center; }
.color-input-wrap input[type="color"] {
  width:44px; height:44px; border:1px solid var(--border);
  border-radius:8px; cursor:pointer; padding:2px;
}
.color-hex { width:100px !important; font-family:monospace; }

.logo-upload-area { display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.logo-preview {
  width:100px; height:60px; border:1px dashed var(--border);
  border-radius:8px; display:flex; align-items:center; justify-content:center;
  color:var(--text-muted); font-size:12px; overflow:hidden;
  background:#F9F9F9;
}
.logo-preview img { max-width:100%; max-height:100%; }
.file-input { display:none; }

.settings-cats .cat-header { margin-bottom:0; }

/* ─── Toast ─── */
.toast {
  position:fixed; bottom:24px; left:50%; transform:translateX(-50%) translateY(80px);
  background:var(--text); color:white; padding:12px 24px;
  border-radius:10px; font:500 14px/1 'Inter',sans-serif;
  box-shadow:0 4px 16px rgba(0,0,0,.2);
  transition: transform .3s, opacity .3s;
  opacity:0; z-index:9999; white-space:nowrap;
  max-width:90vw;
}
.toast.show { transform:translateX(-50%) translateY(0); opacity:1; }

/* ─── Modal ─── */
.modal-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,.4);
  display:flex; align-items:center; justify-content:center;
  z-index:200;
}
.modal-overlay.hidden { display:none; }
.modal {
  background:white; border-radius:14px; width:90%; max-width:500px;
  max-height:80vh; overflow-y:auto; box-shadow:0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display:flex; justify-content:space-between; align-items:center;
  padding:16px 20px; border-bottom:1px solid var(--border);
}
.modal-header h3 { font-size:18px; }
.modal-close {
  background:none; border:none; font-size:24px; cursor:pointer;
  color:var(--text-muted); padding:0 4px;
  min-width:40px; min-height:40px;
  display:flex; align-items:center; justify-content:center;
}
.modal-body { padding:20px; }
.template-item {
  display:flex; justify-content:space-between; align-items:center;
  padding:10px; border:1px solid var(--border); border-radius:8px;
  margin-bottom:8px; cursor:pointer; transition: all .2s;
}
.template-item:hover { border-color:var(--primary); background:#FFF5F7; }
.template-item .t-name { font-weight:600; }
.template-item .t-date { font-size:12px; color:var(--text-muted); }

/* ─── Utilities ─── */
.hidden { display:none !important; }
.muted { color:var(--text-muted); text-align:center; padding:40px 0; }

/* ═══════════════════════════════════
   RESPONSIVE — Tablet (<=768px)
   ═══════════════════════════════════ */
@media (max-width:768px) {
  .form-row { grid-template-columns:1fr; }
  .results-grid { grid-template-columns:1fr; }
  .color-grid { grid-template-columns:1fr; }
  .cats-header { flex-direction:column; align-items:stretch; }
  .cats-actions { justify-content:stretch; }
  .cats-actions .btn { flex:1; text-align:center; }
}

/* ═══════════════════════════════════
   RESPONSIVE — Mobile (<=600px)
   ═══════════════════════════════════ */
@media (max-width:600px) {
  /* Hide desktop header nav, show mobile bottom tab bar */
  .header .nav { display:none; }
  .header-inner { height:48px; justify-content:center; }

  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left:0; right:0;
    z-index: 100;
    background: white;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-nav .mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 0 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: 500 11px/1 'Inter', sans-serif;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color .2s;
    gap: 3px;
    min-height: 52px;
  }
  .mobile-nav .mob-tab .mob-icon { font-size:22px; }
  .mobile-nav .mob-tab.active { color: var(--primary); }
  .mobile-nav .mob-tab:active { opacity:.7; }

  /* Main area padding adjusted for bottom bar */
  .main {
    padding: 12px 12px 80px;
  }

  /* Card compact */
  .card { padding:16px; margin-bottom:14px; }
  .card h2 { font-size:18px; margin-bottom:14px; }

  /* Buttons — finger-friendly */
  .btn { min-height:48px; padding:12px 18px; font-size:15px; }
  .btn-sm { min-height:44px; padding:10px 14px; font-size:14px; }
  .btn-lg { min-height:52px; padding:16px; font-size:17px; }
  .btn-copy { min-height:40px; padding:10px 16px; font-size:13px; }

  /* Categories — single column, full width */
  .category-block { padding:12px; }
  .cat-header { gap:6px; flex-wrap:wrap; }
  .cat-emoji-input { width:44px !important; font-size:18px; }
  .cat-drag { min-width:36px; min-height:36px; font-size:20px; }
  .cat-remove { min-width:36px; min-height:36px; }

  .dishes-list { padding-left:12px; }
  .dish-row { gap:6px; }
  .dish-row input { padding:10px; font-size:15px; }
  .dish-remove { min-width:36px; min-height:36px; font-size:18px; }
  .btn-add-dish { margin-left:12px; padding:10px 14px; font-size:14px; min-height:44px; }

  /* Results stacked */
  .results-grid { grid-template-columns:1fr; gap:16px; }

  /* Text tabs scrollable */
  .text-tabs { gap:6px; }
  .text-tab { padding:10px 16px; font-size:14px; min-height:44px;
    display:flex; align-items:center; }

  .text-output { padding:14px; font-size:13px; }

  /* History cards — stacked layout */
  .history-item {
    flex-direction:column; text-align:center;
    padding:16px; gap:12px;
  }
  .history-thumb { width:100%; height:auto; max-height:200px; object-fit:contain; }
  .history-actions {
    justify-content:center; width:100%; gap:8px;
  }
  .history-actions .btn { flex:1; min-height:48px; }

  /* Settings */
  .color-grid { grid-template-columns:1fr; }
  .color-input-wrap { width:100%; }
  .color-hex { flex:1 !important; width:auto !important; }

  .logo-upload-area { flex-direction:column; align-items:stretch; }
  .logo-preview { width:100%; height:80px; }

  /* Toast above bottom nav */
  .toast { bottom:72px; }

  /* HTML preview compact */
  .html-preview { padding:14px; }
  .hp-header { padding:16px; }
  .hp-header h2 { font-size:20px; }

  /* Form inputs */
  input[type="text"], input[type="date"], select {
    padding:12px 14px; font-size:16px; /* 16px prevents iOS zoom */
  }

  /* Cats actions full width */
  .cats-actions { width:100%; }
  .cats-actions .btn { flex:1; min-height:44px; justify-content:center; }
}

/* ═══════════════════════════════════
   RESPONSIVE — Small phones (<=380px)
   ═══════════════════════════════════ */
@media (max-width:380px) {
  .main { padding:8px 8px 76px; }
  .card { padding:12px; border-radius:10px; }
  .cat-header { gap:4px; }
  .cat-emoji-input { width:38px !important; }
  .hp-header h2 { font-size:17px; }
  .mobile-nav .mob-tab { font-size:10px; }
}
