/* Receptet – varm design. Typsnitt laddas i views/partials/head.ejs. */

:root{
  color-scheme: light;
  --bg: #F7F5F2;
  --card: #FFFFFF;
  --ink: #1F1B18;
  --ink-soft: #4C443F;
  --muted: #6F6761;
  --line: #EDE8E2;
  --o1: #EA4A12;
  --o2: #F7782A;
  --o-ink: #B93A0C;
  --grad: linear-gradient(135deg, var(--o1) 0%, var(--o2) 100%);
  --tint: #FFF0E8;
  --danger: #B3261E;
  --ok: #1F6F4A;
  --shadow: 0 6px 18px -8px rgba(60,30,10,.22);
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --nav-h: 76px;
  --line-strong: #E0D6CB;
  --err-bg: #FDECEA;
  --ok-bg: #E8F4EC;
  --sel: #FFD9C2;
}

@media (prefers-color-scheme: dark){
  :root{
    color-scheme: dark;
    --bg: #171310;
    --card: #231E1A;
    --ink: #F4EDE6;
    --ink-soft: #D8CDC3;
    --muted: #A99F95;
    --line: #362E28;
    --line-strong: #4A3F37;
    --tint: #3B2518;
    --o-ink: #FF9D70;
    --danger: #FFB4AB;
    --ok: #8FD6A8;
    --err-bg: #3A1D1A;
    --ok-bg: #173022;
    --sel: #6A3517;
    --shadow: 0 6px 18px -8px rgba(0,0,0,.6);
  }
}

*{ box-sizing: border-box; }
html{ -webkit-text-size-adjust: 100%; }
body{
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.45;
}
a{ color: var(--o-ink); }
img{ max-width: 100%; }
:focus-visible{ outline: 3px solid var(--ink); outline-offset: 2px; }
::selection{ background: var(--sel); }
h1,h2,h3{ font-family: var(--serif); }

.only-mobile{ display: none !important; }

/* ---------- Gemensamma byggstenar ---------- */
.btn{
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--sans); font-weight: 700; font-size: 16px; line-height: 1;
  min-height: 48px; padding: 0 22px; border-radius: 16px; border: 2px solid transparent;
  background: var(--grad); color: #fff; cursor: pointer; text-decoration: none;
  box-shadow: 0 10px 20px -10px rgba(234,74,18,.7);
}
.btn:hover{ filter: brightness(1.05); }
.btn:active{ transform: translateY(1px); }
.btn.sm{ min-height: 42px; padding: 0 18px; font-size: 15px; border-radius: 14px; }
.btn.block{ width: 100%; }
.btn.secondary{ background: var(--card); color: var(--o-ink); border-color: var(--line); box-shadow: none; }
.btn:disabled{ opacity: .55; cursor: not-allowed; }

.circle{
  width: 42px; height: 42px; border-radius: 50%; background: var(--card); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  box-shadow: var(--shadow); border: 0; cursor: pointer; text-decoration: none; padding: 0;
}
.circle svg{ width: 20px; height: 20px; }
.circle.accent{ color: var(--o-ink); }
.circle.solid{ background: var(--grad); color: #fff; }

.alert{ border-radius: 14px; padding: 12px 16px; font-size: 14.5px; margin-bottom: 16px; font-weight: 500; }
.alert.error{ background: var(--err-bg); color: var(--danger); }
.alert.notice{ background: var(--ok-bg); color: var(--ok); }

.card{ background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 24px; }

.field{ margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label, .lab{ font-size: 13.5px; font-weight: 600; color: var(--ink-soft); margin: 0 2px; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=url], .field input[type=search],
.field select, .field textarea{
  font-family: var(--sans); font-size: 16px; color: var(--ink);
  min-height: 50px; padding: 12px 16px; border-radius: 14px; border: 1.5px solid transparent;
  background: var(--card); box-shadow: var(--shadow); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus{ outline: none; border-color: var(--o1); }
.field textarea{ resize: vertical; min-height: 120px; line-height: 1.55; }
.field input::placeholder, .field textarea::placeholder{ color: #A59D96; }

.review-note{ font-size: 14px; color: var(--muted); margin: 0 2px 16px; line-height: 1.5; }
.review-note a{ font-weight: 600; }

.container{ max-width: 960px; margin: 0 auto; padding: 24px 20px 60px; }
.container.narrow{ max-width: 560px; }
h1.page-title{ font-weight: 700; font-size: 30px; line-height: 1.15; margin: 4px 0 18px; }

/* ---------- Toppfält, kontomeny, bottenmeny ---------- */
.topbar{
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 68px; padding: 10px 28px; background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.brand{ font-family: var(--serif); font-weight: 700; font-size: 24px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.top-actions{ display: flex; align-items: center; gap: 12px; }
.avatar{
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--tint); color: var(--o-ink); font: 700 16px var(--sans);
  display: inline-flex; align-items: center; justify-content: center;
}

.account-sheet{ position: fixed; inset: 0; z-index: 40; background: rgba(31,27,24,.28); display: flex; justify-content: flex-end; align-items: flex-start; padding: 64px 24px 0; }
.account-sheet[hidden]{ display: none; }
.account-card{ background: var(--card); border-radius: 20px; box-shadow: 0 24px 50px -20px rgba(60,30,10,.45); min-width: 240px; padding: 8px; }
.account-who{ padding: 12px 14px 10px; font-size: 14px; color: var(--muted); word-break: break-all; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.account-card a, .account-card button{
  display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 12px; border: 0; background: none;
  font: 600 16px var(--sans); color: var(--ink); text-decoration: none; cursor: pointer;
}
.account-card a:hover, .account-card button:hover{ background: var(--tint); }
.account-card form{ margin: 0; }

.bottom-nav{
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 30;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
  display: flex; gap: 6px;
}
.bottom-nav a, .bottom-nav button{
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font: 600 12.5px var(--sans); color: var(--muted); border-radius: 14px; border: 0; background: none;
  text-decoration: none; cursor: pointer;
}
.bottom-nav svg{ width: 23px; height: 23px; }
.bottom-nav .on{ color: var(--o-ink); background: var(--tint); }

/* ---------- Inloggning ---------- */
.login-wrap{ min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card{ width: 100%; max-width: 420px; background: var(--card); border-radius: 32px; box-shadow: 0 30px 60px -30px rgba(80,30,10,.45); overflow: hidden; }
.login-hero{ height: 250px; background: linear-gradient(135deg, #FF5A1F 0%, #FF8F3F 100%); position: relative; overflow: hidden; border-radius: 0 0 46% 46% / 0 0 40px 40px; }
.login-hero .blob{ position: absolute; border-radius: 50%; background: rgba(255,255,255,.16); }
.login-hero .e{ position: absolute; filter: drop-shadow(0 10px 10px rgba(90,30,0,.3)); line-height: 1; }
.login-body{ padding: 26px 26px 30px; }
.login-body .mark{ display: block; text-align: center; font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1.15; margin-bottom: 6px; }
.login-body .tag{ text-align: center; color: var(--muted); font-size: 15px; margin-bottom: 22px; }
.login-body .hint{ text-align: center; font-size: 13.5px; color: var(--muted); margin: 16px 0 0; }
.error-card{ padding: 32px 26px; text-align: center; max-width: 420px; width: 100%; }
.error-card p{ margin: 0 0 18px; font-size: 17px; }

/* ---------- Bläddra bland recept ---------- */
.app{ display: grid; grid-template-columns: 276px minmax(0, 1fr); align-items: start; }
.sidebar, .main{ min-width: 0; }
.sidebar{ position: sticky; top: 68px; max-height: calc(100vh - 68px); overflow-y: auto; padding: 8px 14px 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.search-wrap{ position: relative; }
.search-wrap input{
  width: 100%; height: 50px; font: 500 15.5px var(--sans); color: var(--ink); background: var(--card);
  border: 1.5px solid transparent; border-radius: 25px; padding: 0 14px 0 44px; box-shadow: var(--shadow);
}
.search-wrap input:focus{ outline: none; border-color: var(--o1); }
.search-wrap input::placeholder{ color: #8F8780; }
.search-wrap svg{ position: absolute; left: 17px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }

.cat-list{ display: flex; flex-direction: column; gap: 2px; }
.cat-btn{
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  min-height: 42px; padding: 0 14px; border-radius: 13px; border: 0; background: transparent;
  color: var(--ink-soft); font: 500 15.5px var(--sans); cursor: pointer;
}
.cat-btn:hover{ background: var(--card); }
.cat-btn .name{ flex: 1; }
.cat-btn .count{ font-size: 12.5px; font-weight: 600; color: var(--muted); }
.cat-btn[aria-pressed="true"]{ background: var(--grad); color: #fff; font-weight: 700; box-shadow: 0 8px 16px -8px rgba(234,74,18,.8); }
.cat-btn[aria-pressed="true"] .count{ color: rgba(255,255,255,.9); }

.main{ padding: 8px 28px 60px 14px; min-width: 0; }
.main-header{ display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.main-header h1{ font-weight: 700; font-size: 32px; line-height: 1.1; margin: 0; }
.result-count{ font-size: 14px; color: var(--muted); }

.grid{ display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.rcard{
  background: var(--card); border: 0; border-radius: 22px; padding: 8px; text-align: left; cursor: pointer;
  box-shadow: var(--shadow); display: flex; flex-direction: column; color: var(--ink); min-width: 0; font: inherit;
}
.rcard:hover{ transform: translateY(-2px); }
.rcard h3{ font-weight: 600; font-size: 17px; line-height: 1.22; margin: 12px 6px 8px; min-height: 42px; overflow-wrap: anywhere; }
.rcard .meta{ display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0 6px 8px; font-size: 12.5px; color: var(--muted); }
.rcard .meta b{ flex: none; font-weight: 600; color: var(--o-ink); background: var(--tint); border-radius: 10px; padding: 3px 9px; font-size: 12px; white-space: nowrap; }
.rcard .meta em{ font-style: normal; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shared-by{ display: block; margin: -2px 6px 8px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tile{ position: relative; border-radius: 16px; aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--tile-bg, var(--t, #FFE8C7)); }
.tile::before{ content: ""; position: absolute; width: 120%; height: 120%; left: -10%; top: -30%; background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.65), rgba(255,255,255,0) 55%); }
.tile::after{ content: ""; position: absolute; width: 150px; height: 150px; border-radius: 50%; right: -50px; bottom: -60px; background: rgba(255,255,255,.35); }
.tile span{ position: relative; z-index: 1; font-size: 52px; line-height: 1; filter: drop-shadow(0 6px 6px rgba(80,40,10,.22)); }

.empty{ padding: 60px 20px; text-align: center; color: var(--muted); }
.empty .big{ font-family: var(--serif); font-size: 22px; color: var(--ink); margin-bottom: 6px; }

/* ---------- Receptvy (ruta över listan) ---------- */
.overlay{ position: fixed; inset: 0; background: rgba(31,27,24,.5); display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.overlay[hidden]{ display: none; }
.detail{ background: var(--bg); border-radius: 28px; max-width: 640px; width: 100%; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); position: relative; overflow: hidden; outline: none; }
.detail .dhero .tile{ aspect-ratio: auto; height: 230px; border-radius: 0; }
.detail .dhero .tile span{ font-size: 104px; margin-top: -8px; }
.detail-actions{ position: absolute; top: 16px; left: 16px; right: 16px; display: flex; justify-content: space-between; z-index: 3; }
.detail-actions-right{ display: flex; gap: 10px; }
.detail-body{ position: relative; z-index: 2; margin-top: -28px; background: var(--bg); border-radius: 28px 28px 0 0; padding: 26px 24px 32px; }
.detail h2{ font-weight: 700; font-size: 30px; line-height: 1.12; margin: 0 0 12px; overflow-wrap: anywhere; }
.pills{ display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.pill{ height: 32px; padding: 0 13px; border-radius: 16px; background: var(--tint); color: var(--o-ink); font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; }
.pill.plain{ background: var(--card); color: var(--ink-soft); box-shadow: 0 2px 8px -4px rgba(60,30,10,.25); }
.detail h4{ font-family: var(--serif); font-size: 20px; font-weight: 600; margin: 0 0 10px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.ing-list{ background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 4px 18px; margin-bottom: 24px; }
.ing-list div{ padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.ing-list div:last-child{ border-bottom: 0; }
.steps{ margin-bottom: 8px; }
.step{ display: flex; gap: 12px; margin-bottom: 16px; font-size: 16px; line-height: 1.6; }
.step i{ flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--grad); color: #fff; font-style: normal; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.step-plain{ font-size: 16px; line-height: 1.65; white-space: pre-wrap; }
.anteckning{ margin-top: 18px; font-size: 14.5px; line-height: 1.55; color: var(--muted); background: var(--card); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); }

/* ---------- Lägg till / redigera recept ---------- */
.mode-tabs{ display: flex; gap: 4px; background: var(--card); border-radius: 24px; padding: 4px; box-shadow: var(--shadow); margin-bottom: 18px; }
.mode-tab{
  flex: 1; min-height: 42px; border-radius: 20px; border: 0; background: transparent; color: var(--ink-soft);
  font: 600 14.5px var(--sans); cursor: pointer; padding: 0 8px;
}
.mode-tab[aria-selected="true"]{ background: var(--grad); color: #fff; box-shadow: 0 6px 12px -6px rgba(234,74,18,.8); }
.mode-panel[hidden]{ display: none; }
.panel{ margin-bottom: 20px; }

.record-btn{ display: inline-flex; align-items: center; gap: 10px; }
.record-btn .dot{ width: 10px; height: 10px; border-radius: 50%; background: var(--danger); display: none; }
.record-btn.recording .dot{ display: inline-block; animation: pulse 1s infinite; }
@keyframes pulse{ 0%,100%{ opacity: 1; } 50%{ opacity: .25; } }

.photo-drop{ display: block; border: 2px dashed var(--line-strong); border-radius: 18px; padding: 28px 18px; text-align: center; color: var(--muted); font-size: 15px; cursor: pointer; background: var(--card); }
.photo-drop img{ max-height: 260px; border-radius: 12px; margin-top: 10px; }

.spinner{ width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin{ to{ transform: rotate(360deg); } }

.kchips{ display: flex; flex-wrap: wrap; gap: 8px; }
.kchip{ position: relative; }
.kchip input{ position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.kchip span{ display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 20px; background: var(--card); color: var(--ink-soft); font-weight: 600; font-size: 14.5px; box-shadow: 0 2px 8px -4px rgba(60,30,10,.25); }
.kchip input:checked + span{ background: var(--grad); color: #fff; box-shadow: 0 8px 16px -8px rgba(234,74,18,.8); }
.kchip input:focus-visible + span{ outline: 3px solid var(--ink); outline-offset: 2px; }
.field-group{ margin-bottom: 18px; }
.form-actions{ display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
#parseStatus:empty{ display: none; }
#parseStatus{ margin-top: 14px; }
#parseStatus .alert{ margin-bottom: 0; }

/* ---------- Tidigare versioner ---------- */
.version{ margin-bottom: 16px; }
.version h4{ font-family: var(--serif); font-size: 18px; margin: 16px 0 6px; font-weight: 600; }
.version .when{ font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.version .body{ white-space: pre-wrap; font-size: 15.5px; line-height: 1.6; }

/* ---------- Användare (admin) ---------- */
table.users{ width: 100%; border-collapse: collapse; font-size: 15px; }
table.users th, table.users td{ text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); }
table.users th{ color: var(--muted); font-weight: 600; font-size: 13px; }
table.users td{ overflow-wrap: anywhere; }
.role-pill{ font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--card); box-shadow: 0 2px 8px -4px rgba(60,30,10,.25); color: var(--ink-soft); }
.role-pill.admin{ background: var(--tint); color: var(--o-ink); }
.section-title{ font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 0 0 8px; }

/* ---------- Användare och delning ---------- */
.stack{ display: flex; flex-direction: column; gap: 12px; }
.user-row{ display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 16px 18px; }
.user-main{ min-width: 0; flex: 1 1 200px; }
.user-email{ font-weight: 600; overflow-wrap: anywhere; }
.user-meta{ display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-size: 13.5px; color: var(--muted); }
.user-actions{ display: flex; gap: 8px; align-items: center; }
.user-actions form{ margin: 0; }
.btn.danger{ background: transparent; color: var(--danger); border-color: var(--danger); box-shadow: none; }
.btn.danger:hover{ background: var(--err-bg); filter: none; }

.check-list{ display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.check-row{ display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px; background: var(--bg); border-radius: 14px; cursor: pointer; }
.check-row input{ width: 22px; height: 22px; accent-color: var(--o1); flex: none; margin: 0; }
.check-row span{ overflow-wrap: anywhere; font-weight: 500; }
.check-row small{ display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.plain-list{ margin: 0; padding-left: 20px; }
.plain-list li{ margin-bottom: 4px; overflow-wrap: anywhere; }
code{ font-family: ui-monospace, Menlo, monospace; font-size: .92em; background: var(--bg); padding: 1px 6px; border-radius: 6px; }

/* ---------- Mobil ---------- */
@media (max-width: 860px){
  .only-desktop{ display: none !important; }
  .only-mobile{ display: flex !important; }
  body{ padding-bottom: calc(var(--nav-h) + 12px); }

  .topbar{ padding: 8px 18px; min-height: 60px; }
  .brand{ font-size: 23px; }
  .account-sheet{ align-items: flex-end; justify-content: center; padding: 0 12px calc(var(--nav-h) + 8px); }
  .account-card{ width: 100%; }

  .app{ grid-template-columns: minmax(0, 1fr); }
  .sidebar{ position: static; max-height: none; overflow: visible; padding: 4px 18px 6px; gap: 14px; }
  .cat-list{ flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 8px; margin: 0 -18px; padding: 2px 18px 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .cat-list::-webkit-scrollbar{ display: none; }
  .cat-btn{ width: auto; flex: none; white-space: nowrap; min-height: 40px; padding: 0 16px; border-radius: 20px; background: var(--card); box-shadow: 0 2px 8px -4px rgba(60,30,10,.25); font-weight: 600; font-size: 14.5px; }
  .cat-btn .count{ display: none; }
  .main{ padding: 8px 18px 24px; }
  .main-header h1{ font-size: 26px; }
  .grid{ grid-template-columns: 1fr 1fr; gap: 12px; }
  .rcard h3{ font-size: 15.5px; margin: 10px 4px 6px; min-height: 38px; }
  .rcard .meta{ margin: 0 4px 6px; flex-wrap: wrap; row-gap: 4px; }
  .tile span{ font-size: 46px; }

  .container{ padding: 8px 18px 28px; }
  h1.page-title{ font-size: 26px; }
  .card{ padding: 20px; border-radius: 20px; }

  .overlay{ padding: 0; }
  .detail{ border-radius: 0; min-height: 100vh; max-width: none; }
  .detail-actions{ position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 14px; right: 14px; }
  .detail-body{ padding: 24px 18px 36px; }
  .detail h2{ font-size: 27px; }

  .login-wrap{ padding: 0; align-items: stretch; }
  .login-card{ max-width: none; border-radius: 0; min-height: 100vh; box-shadow: none; display: flex; flex-direction: column; }
  .login-hero{ height: 300px; flex: none; }
  .login-body{ flex: 1; }
}

@media (max-width: 380px){
  .mode-tab{ font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{ animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .rcard:hover{ transform: none; }
}
.ing-list .sub{ font-family: var(--serif); font-weight: 600; font-size: 16.5px; padding-top: 16px; }

/* ---------- Mörkt läge: överskrivningar (måste ligga efter basreglerna) ---------- */
@media (prefers-color-scheme: dark){
  .tile{ --tile-bg: var(--td, #4A3F37); }
  .tile::before{ background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.22), rgba(255,255,255,0) 55%); }
  .tile::after{ background: rgba(255,255,255,.08); }
  .account-card{ box-shadow: 0 24px 50px -20px rgba(0,0,0,.8); }
  .overlay, .account-sheet{ background: rgba(0,0,0,.6); }
}
