:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: #20302d;
  background: #f3f6f4;
  --green: #123b35;
  --green-soft: #e3eeea;
  --gold: #edc66e;
  --muted: #71807c;
  --line: #e0e7e3;
  --surface: #fff;
  --danger: #a33a32;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: 82px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  min-height: 72px;
  padding: 12px max(20px, calc((100vw - 1200px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 3px 14px #102d2922;
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand img { border-radius: 12px; }
.brand span { display: grid; gap: 2px; }
.brand small { color: #d1dfda; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.connection { color: #d1dfda; font-size: .85rem; white-space: nowrap; }
.connection::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e1ad4b; margin-inline-end: 7px; }
.connection.online::before { background: #62d09d; }
.connection.offline::before { background: #ee786d; }
.icon-button { border: 0; border-radius: 10px; padding: 7px 12px; color: inherit; background: #ffffff1a; font-size: 1.3rem; }
.icon-button:disabled, button:disabled { opacity: .55; cursor: not-allowed; }
.button { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 700; }
.button.primary { color: #fff; background: var(--green); }
.button.quiet { color: inherit; background: transparent; border-color: #ffffff50; }
.button:focus-visible, .icon-button:focus-visible, .nav-item:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #e7b957; outline-offset: 2px; }

.login-panel { width: min(480px, calc(100% - 32px)); margin: 12vh auto 40px; padding: 30px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 15px 45px #123b3512; }
.login-panel h1 { margin: 6px 0 12px; color: var(--green); font-size: 2rem; }
.login-panel p { line-height: 1.65; }
.eyebrow { margin: 0 0 5px; color: #688278; font-size: .78rem; font-weight: 800; letter-spacing: .03em; }
.muted { color: var(--muted); font-size: .9rem; }
#googleSignIn { min-height: 48px; margin: 22px 0 8px; }

#appRoot { width: min(1200px, calc(100% - 36px)); margin: 28px auto 0; }
.view { display: none; }
.view.active { display: block; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin: 6px 0 24px; }
.page-heading h1 { margin: 0; color: var(--green); font-size: clamp(1.5rem, 4vw, 2.2rem); }
.page-heading p { margin: 7px 0 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-bottom: 18px; }
.metric-card { min-height: 114px; padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); display: flex; flex-direction: column; gap: 7px; }
.metric-label { color: var(--muted); font-size: .85rem; }
.metric-value { color: var(--green); font-size: 1.7rem; }
.metric-foot { color: var(--muted); font-size: .78rem; }
.metric-card.alert .metric-value { color: var(--danger); }
.dashboard-grid, .settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { margin: 14px 0; padding: 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.panel h2 { margin: 0 0 14px; color: var(--green); font-size: 1.08rem; }
.reminders-heading { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.reminders-heading p { margin: -7px 0 12px; }
.reminders-heading > span { white-space: nowrap; }
.delivery-reminders { max-height: 460px; overflow-y: auto; padding-inline-end: 2px; }
.reminder-item { text-align: start; }
.reminder-date { display: grid; justify-items: end; gap: 5px; color: var(--muted); font-size: .82rem; }
.section-list, .compact-list, .orders-list { display: grid; gap: 9px; }
.customers-list { display: grid; gap: 12px; }
.customer-search { margin-bottom: 12px; }
.customer-card { padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.customer-heading { display: flex; justify-content: space-between; gap: 10px; }
.customer-heading strong { color: var(--green); }
.customer-heading span, .customer-phone { color: var(--muted); font-size: .85rem; }
.customer-phone { display: inline-block; margin-top: 5px; direction: ltr; }
.customer-orders { display: grid; gap: 7px; margin-top: 12px; }
.customer-order { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; text-align: start; background: #fff; }
.customer-order > span:first-child { display: grid; gap: 3px; }
.customer-order small { color: var(--muted); }
.section-row, .compact-item { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; color: inherit; background: #fff; text-align: right; }
.section-row:hover, .compact-item:hover, .order-card:hover { border-color: #a2bbb1; background: #f8fbf9; }
.section-row span:first-child, .compact-main { display: grid; gap: 4px; }
.section-row small, .compact-item small { color: var(--muted); }
.section-badge { color: var(--green); font-weight: 800; }
.compact-item { text-align: right; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 17px; }
.search-box { flex: 1 1 250px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.search-box input { width: 100%; min-height: 42px; border: 0; outline: 0; }
select, input, textarea { color: inherit; }
.filter-bar select, .report-controls select { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; background: #fff; }
.checkbox-filter { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.order-card { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: #fff; cursor: pointer; }
.order-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.order-subtitle { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; color: var(--muted); font-size: .82rem; }
.order-side { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; }
.status-pill, .priority-pill, .archive-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; background: var(--green-soft); color: var(--green); font-size: .75rem; white-space: nowrap; }
.status-pill.late, .priority-pill.high { background: #fae8e5; color: #9b332c; }
.status-pill.soon { background: #fff2d5; color: #855c12; }
.status-pill.done { background: #e3f2e8; color: #276543; }
.archive-pill { background: #edf0ef; color: #61706c; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }

.report-controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.report-controls label { display: grid; gap: 6px; color: var(--muted); font-size: .85rem; }
.annual-chart { min-height: 155px; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: end; gap: 7px; }
.month-bar { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: .7rem; }
.month-bar-track { height: 98px; width: 100%; display: flex; align-items: end; overflow: hidden; border-radius: 5px 5px 0 0; background: #edf2ef; }
.month-bar-fill { width: 100%; min-height: 2px; background: #498b70; }
.month-bar-count { color: var(--green); font-weight: 700; }
.details-list { display: grid; grid-template-columns: minmax(115px, .8fr) 1.5fr; gap: 9px 16px; margin: 0; }
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.order-fields { display: grid; gap: 10px; }
.field-row { display: grid; grid-template-columns: minmax(120px, .7fr) 1.3fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field-row span:first-child { color: var(--muted); }
.field-link { color: var(--green); text-decoration: underline; text-underline-offset: 3px; }
.field-link:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; border-radius: 3px; }
.order-history { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.order-history h3 { margin: 0 0 10px; color: var(--green); }
.history-list { display: grid; gap: 8px; }
.history-item { padding: 10px 12px; border-radius: 10px; background: #f3f6f4; overflow-wrap: anywhere; }
.history-heading { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; }
.history-heading time, .history-item small { color: var(--muted); font-size: .8rem; }
.history-item p { margin: 8px 0 5px; }
.field-editor { display: grid; gap: 7px; }
.field-editor input, .field-editor select, .field-editor textarea, .form-grid input, .form-grid select, .form-grid textarea { width: 100%; min-height: 41px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: #fff; }
.field-editor textarea, .form-grid textarea { resize: vertical; }
.field-editor button { justify-self: start; }
.error-list { display: grid; gap: 8px; }
.error-item, .message.error { color: #8e2d26; background: #fae8e5; }
.error-item { padding: 9px 11px; border-radius: 9px; overflow-wrap: anywhere; }
.notice { padding: 12px 14px; border-radius: 10px; color: #66511f; background: #fff3d7; line-height: 1.6; }
.notice a { color: inherit; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.user-admin-form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(240px, 1fr) auto; align-items: end; gap: 12px; }
.user-admin-form label { display: grid; gap: 6px; color: var(--muted); font-size: .85rem; }
.user-admin-form input, .user-admin-form select { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: #fff; }
.user-list { display: grid; gap: 8px; margin-top: 14px; }
.user-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.user-row > div { display: grid; gap: 4px; overflow-wrap: anywhere; }
.user-row small, .user-row > span { color: var(--muted); font-size: .82rem; }
.user-row > span { text-align: end; }
.message { padding: 10px 12px; border-radius: 9px; line-height: 1.55; }
.message.success { color: #205d3f; background: #e3f2e8; }
.message.error { border: 0; }
.bottom-nav { position: fixed; z-index: 5; inset: auto 0 0; display: flex; justify-content: center; gap: 4px; padding: 8px max(10px, calc((100vw - 900px) / 2)) calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fffffff2; backdrop-filter: blur(10px); }
.nav-item { flex: 1; max-width: 150px; min-height: 48px; padding: 7px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-weight: 700; }
.nav-item.active { color: var(--green); background: var(--green-soft); }
.nav-item.add-nav { color: #fff; background: var(--green); }
.desktop-add { display: none; }

.app-dialog { width: min(700px, calc(100% - 22px)); max-height: min(88vh, 850px); padding: 22px; border: 0; border-radius: 18px; color: inherit; background: #fff; box-shadow: 0 20px 80px #0004; }
.app-dialog::backdrop { background: #10231fcc; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-heading h2 { margin: 0; color: var(--green); }
.dialog-heading .icon-button { color: var(--green); background: var(--green-soft); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: .85rem; }
#newNotesGroup { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 17px; }
.loading-overlay { position: fixed; z-index: 10; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; background: #f3f6f4ec; color: var(--green); font-weight: 700; }
.spinner { width: 25px; height: 25px; border: 3px solid #cad8d1; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .bottom-nav { position: static; width: min(1200px, calc(100% - 36px)); margin: 22px auto 0; padding: 0; border: 0; background: transparent; }
  .nav-item { max-width: 155px; background: #fff; border: 1px solid var(--line); }
  .desktop-add { display: inline-block; }
  .add-nav { display: none; }
}
@media (max-width: 700px) {
  .topbar { min-height: 64px; padding: 10px 14px; }
  .connection { font-size: .75rem; }
  #appRoot { width: calc(100% - 22px); margin-top: 20px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric-card { min-height: 100px; padding: 13px; }
  .metric-value { font-size: 1.45rem; }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; gap: 2px; }
  .page-heading { align-items: start; }
  .page-heading .desktop-add { display: none; }
  .order-card { align-items: start; flex-direction: column; }
  .order-side { justify-content: start; }
  .filter-bar > select { flex: 1 1 42%; }
  .checkbox-filter { flex: 1 1 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .user-admin-form { grid-template-columns: 1fr; }
  .user-row { align-items: start; flex-direction: column; }
  .user-row > span { text-align: start; }
  .reminders-heading { flex-direction: column; }
  .reminders-heading > span { white-space: normal; }
  .reminder-item { align-items: start; flex-direction: column; }
  .reminder-date { justify-items: start; }
  #newNotesGroup { grid-column: auto; }
  .app-dialog { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: 92vh; margin: 0; border-radius: 20px 20px 0 0; padding: 20px 16px calc(18px + env(safe-area-inset-bottom)); }
  .field-row { grid-template-columns: 1fr; gap: 7px; }
  .report-controls label { flex: 1 1 30%; }
  .report-controls select { width: 100%; }
  .annual-chart { gap: 3px; }
}
@media (max-width: 420px) {
  .bottom-nav { gap: 1px; padding-inline: 4px; }
  .nav-item { min-width: 0; padding: 6px 2px; font-size: .7rem; white-space: nowrap; }
}
