/* Rabbit Farm — application stylesheet (light theme, mobile-first, no frameworks). */

:root {
  --green-50: #eef7f1;
  --green-100: #d9eee2;
  --green-600: #1f7a45;
  --green-700: #186339;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #1c2a22;
  --muted: #64736a;
  --border: #e1e8e3;
  --danger: #c0392b;
  --danger-bg: #fdeceb;
  --warn: #b7791f;
  --warn-bg: #fff6e0;
  --info: #2563a8;
  --info-bg: #eaf2fc;
  --ok-bg: #e8f6ee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 28, .05), 0 4px 14px rgba(20, 40, 28, .05);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: var(--green-600); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--green-50); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
:focus-visible { outline: 3px solid rgba(31, 122, 69, .4); outline-offset: 2px; }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--green-600); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 300; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---- Buttons ------------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, opacity .15s; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--green-50); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-busy { opacity: .65; cursor: progress; }
.btn.is-busy::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--green-50); text-decoration: none; }

/* ---- Forms -------------------------------------------------------------- */
.form { display: grid; gap: 14px; margin-top: 16px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.req { color: var(--danger); }
.input-wrap { position: relative; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--text); background: #fff;
  border: 1px solid #cfd9d2; border-radius: 10px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(31, 122, 69, .15); }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field.has-error input:focus, .field.has-error select:focus { box-shadow: 0 0 0 3px rgba(192, 57, 43, .15); }
.field-error { min-height: 0; margin: 4px 0 0; font-size: .82rem; color: var(--danger); }
.field-error:empty { display: none; }
.help { margin: 4px 0 0; font-size: .8rem; color: var(--muted); }
.static-value { margin: 0; padding: 10px 0; font-weight: 500; }
.reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; }
.input-wrap input[type=password], .input-wrap input[data-revealed] { padding-right: 44px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400 !important; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--green-600); }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.row-end { text-align: right; margin: -6px 0 0; font-size: .88rem; }
.form-actions { display: flex; justify-content: flex-end; }

/* ---- Notices / banner --------------------------------------------------- */
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; margin: 12px 0 0; font-size: .9rem; }
.notice .icon { margin-top: 1px; }
.notice-error { background: var(--danger-bg); color: #8f2a20; }
.notice-success { background: var(--ok-bg); color: var(--green-700); }
.notice-warning { background: var(--warn-bg); color: #8a5a10; }
.notice-info { background: var(--info-bg); color: var(--info); }
.inline-flash:empty { display: none; }
.banner { display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: var(--warn-bg); color: #8a5a10; font-size: .88rem; }

/* ---- Auth pages --------------------------------------------------------- */
.auth-body { background: linear-gradient(180deg, var(--green-50), var(--bg) 40%); min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.auth-brand { margin-bottom: 18px; }
.auth-title { font-size: 1.4rem; margin-bottom: .2em; }
.auth-alt { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: .92rem; }
.auth-foot { margin-top: 16px; color: var(--muted); font-size: .8rem; }
.state-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 12px; background: var(--green-50); color: var(--green-600); }
.state-icon .icon { width: 28px; height: 28px; }
.state-warn { background: var(--warn-bg); color: var(--warn); }
.state-bad { background: var(--danger-bg); color: var(--danger); }
.actions { margin-top: 16px; }
.error-card { text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--green-600); margin: 0; line-height: 1; }

/* ---- Brand -------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--green-600); color: #fff; display: grid; place-items: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); font-size: .72rem; }

/* ---- App shell ---------------------------------------------------------- */
.shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); max-width: 84vw; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; transform: translateX(-100%); transition: transform .22s ease; z-index: 120; overflow-y: auto; }
.sidebar.is-open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
.sidebar-head { padding: 4px 8px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: #3b4a41; font-weight: 500; text-decoration: none; }
.nav-link:hover { background: var(--green-50); text-decoration: none; }
.nav-link.is-active { background: var(--green-600); color: #fff; }
.nav-link.is-soon { color: #9aa8a0; cursor: default; }
.nav-link.is-soon:hover { background: transparent; }
.nav-link em { margin-left: auto; font-style: normal; font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; background: var(--bg); padding: 2px 6px; border-radius: 6px; }
.nav-divider { border: 0; border-top: 1px solid var(--border); margin: 10px 8px; width: calc(100% - 16px); }
.nav-badge, .bell-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: .68rem; min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; font-weight: 700; }
.nav-badge { margin-left: auto; }
.bell-badge { position: absolute; top: 3px; right: 3px; }
.plan-card { margin-top: auto; padding: 12px; border-radius: 10px; background: var(--green-50); border: 1px solid var(--green-100); display: flex; flex-direction: column; font-size: .85rem; }
.plan-card span { color: var(--green-700); }
.scrim { position: fixed; inset: 0; background: rgba(15, 30, 22, .45); z-index: 110; }

.main { min-width: 0; padding-bottom: 76px; }
.topbar { position: sticky; top: 0; z-index: 90; height: var(--topbar-h); display: flex; align-items: center; gap: 8px; padding: 0 12px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-title { font-weight: 700; }
.topbar-spacer { flex: 1; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--ok-bg); color: var(--green-700); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-pill.is-offline { background: var(--warn-bg); color: var(--warn); }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 10px; background: transparent; border: 0; padding: 4px; border-radius: 10px; cursor: pointer; font: inherit; color: inherit; text-align: left; }
.user-btn:hover { background: var(--green-50); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green-100); color: var(--green-700); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.user-meta { display: none; flex-direction: column; line-height: 1.2; }
.user-meta small { color: var(--muted); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 130; }
.menu a, .menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; background: transparent; border-radius: 8px; font: inherit; color: var(--text); cursor: pointer; text-decoration: none; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--green-50); text-decoration: none; }
.menu-danger { color: var(--danger) !important; }

.view { padding: 18px 14px 28px; max-width: 1100px; margin: 0 auto; outline: none; display: grid; gap: 16px; }
.view.is-loading { opacity: .55; pointer-events: none; transition: opacity .15s; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; }
.page-head h1 { margin: 0; }
.page-head p { margin: 2px 0 0; }
.date-chip { padding: 8px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-size: .85rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: .6em; }
.welcome { display: flex; gap: 16px; align-items: flex-start; }
.welcome-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--green-50); color: var(--green-600); display: grid; place-items: center; flex: none; }
.welcome h2 { margin-bottom: .2em; }
.grid-cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-value { font-size: 1.9rem; line-height: 1.1; }
.stat-text { font-size: 1.2rem; }
.stat-note { font-size: .8rem; color: var(--muted); }
.roadmap { margin: 0; padding-left: 1.1em; color: var(--muted); display: grid; gap: 4px; }
.empty { text-align: center; padding: 36px 18px; }

.list { list-style: none; margin: 0; padding: 0; }
.notif { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.notif:last-child { border-bottom: 0; }
.notif-dot { width: 9px; height: 9px; border-radius: 50%; background: transparent; margin-top: 7px; flex: none; }
.notif.is-unread { background: var(--green-50); }
.notif.is-unread .notif-dot { background: var(--green-600); }
.notif-body { flex: 1; min-width: 0; }
.notif-body p { margin: 2px 0; color: #3b4a41; }

.pref-table { display: grid; gap: 2px; margin-top: 8px; }
.pref-row { display: grid; grid-template-columns: 1fr 64px 64px; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pref-head { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pref-head span:not(:first-child) { text-align: center; }
.pref-label { display: flex; flex-direction: column; }
.switch { display: flex; justify-content: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 40px; height: 24px; border-radius: 999px; background: #cbd5ce; position: relative; transition: background .15s; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--green-600); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:disabled + .switch-ui { opacity: .55; }
.switch input:focus-visible + .switch-ui { outline: 3px solid rgba(31, 122, 69, .4); outline-offset: 2px; }

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 16px; font-size: .7rem; color: var(--muted); text-decoration: none; border-radius: 10px; }
.bottom-nav a.is-active { color: var(--green-600); font-weight: 700; }

/* ---- Toasts ------------------------------------------------------------- */
.toast-region { position: fixed; z-index: 400; left: 12px; right: 12px; bottom: 84px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; align-items: center; }
.toast { pointer-events: auto; width: 100%; max-width: 420px; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: 10px; box-shadow: 0 8px 28px rgba(20, 40, 28, .18); animation: toast-in .2s ease; }
.toast.t-success { border-left-color: var(--green-600); }
.toast.t-error { border-left-color: var(--danger); }
.toast.t-warning { border-left-color: var(--warn); }
.toast .icon { margin-top: 1px; }
.toast.t-success .icon { color: var(--green-600); }
.toast.t-error .icon { color: var(--danger); }
.toast.t-warning .icon { color: var(--warn); }
.toast.t-info .icon { color: var(--info); }
.toast-msg { flex: 1; font-size: .9rem; }
.toast-x { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0; width: 22px; height: 22px; }

/* ---- Modal -------------------------------------------------------------- */
.modal-root { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; padding: 16px; background: rgba(15, 30, 22, .5); }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 16px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop-in .18s ease; }
.modal h2 { font-size: 1.15rem; margin-bottom: .4em; }
.modal-body { color: #3b4a41; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ---- Loading indicators ------------------------------------------------- */
.loader { position: fixed; inset: 0; z-index: 600; display: grid; place-items: center; background: rgba(255, 255, 255, .6); }
.loader-box { display: flex; align-items: center; gap: 12px; padding: 14px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--green-100); border-top-color: var(--green-600); animation: spin .8s linear infinite; }
.progress-bar { position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 700; background: linear-gradient(90deg, transparent, var(--green-600), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: slide 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { from { background-position: -50% 0; } to { background-position: 150% 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---- Phase 2: offline engine UI ----------------------------------------- */
button.status-pill { border: 0; cursor: pointer; font-family: inherit; }
button.status-pill:focus-visible { outline: 2px solid var(--green-600); outline-offset: 2px; }
.status-pill.is-syncing { background: var(--info-bg); color: var(--info); }
.status-pill.is-syncing .dot { animation: pulse 1s ease-in-out infinite; }
.status-pill.is-pending { background: var(--warn-bg); color: var(--warn); }
.status-pill.is-attention, .status-pill.is-auth { background: var(--danger-bg); color: var(--danger); }
.banner.banner-warn { background: var(--warn-bg); color: #8a5a10; }
.banner-action { justify-content: space-between; flex-wrap: wrap; }
.banner-text { flex: 1 1 220px; }
.banner[hidden], .offline-only[hidden] { display: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--ok-bg); color: var(--green-700); white-space: nowrap; }
.badge-pending { background: var(--warn-bg); color: var(--warn); }
.badge-syncing { background: var(--info-bg); color: var(--info); }
.badge-failed, .badge-conflict { background: var(--danger-bg); color: var(--danger); }

.module-root { display: grid; gap: 14px; }
.module-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.module-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.notes-list { display: grid; gap: 12px; }
.note { padding: 14px 16px; }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; }
.note h3 { margin: 6px 0 4px; font-size: 1.02rem; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; color: #33443a; }
.note-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.note-error { margin-top: 8px; color: var(--danger); font-size: .85rem; }
.note.state-failed, .note.state-conflict { border-color: var(--danger); }
.note.state-pending, .note.state-syncing { border-color: #e9c77a; }
.empty-small { padding: 14px; text-align: center; color: var(--muted); }

.sync-panel { display: grid; gap: 12px; }
.queue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.queue-item { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.queue-item.state-failed, .queue-item.state-conflict { border-color: var(--danger); }
.queue-main { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.queue-kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.queue-detail { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.queue-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.offline-shell .main { margin-left: 0; }
.offline-shell .sidebar { display: none; }

@keyframes pulse { 50% { opacity: .35; } }

/* ---- Responsive --------------------------------------------------------- */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-cards { grid-template-columns: repeat(3, 1fr); }
  .user-meta { display: flex; }
  .auth-card { padding: 32px; }
}
@media (min-width: 960px) {
  .sidebar { transform: none; box-shadow: none; }
  .main { margin-left: var(--sidebar-w); padding-bottom: 0; }
  .only-mobile, .bottom-nav, .scrim { display: none !important; }
  .view { padding: 24px 28px 40px; }
  .toast-region { bottom: 20px; left: auto; right: 20px; align-items: flex-end; }
}
