/*
 * WarungTetangga.com — global stylesheet
 *
 * Retrofit pass: applies a cohesive visual design to the whole app via plain
 * semantic-element selectors, with (almost) no markup changes required in
 * public/index.php. Every page already flows through
 * App\Support\Layout::render(), so linking this one file (see Layout.php)
 * styles every route: customer, merchant and admin.
 *
 * Brand: warm, approachable, trustworthy "neighborhood marketplace" look.
 * Palette anchored on the existing PWA brand green from manifest.json /
 * Layout.php's <meta name="theme-color"> (#2e7d32) — no new colors invented.
 *
 * Scope: mobile-first PWA. No CSS framework, no build step, no CDN — a
 * single hand-written file, loaded statically from /assets/app.css.
 * Dark mode intentionally out of scope for this pass.
 */

/* ---------------------------------------------------------------------
   1. Design tokens
   --------------------------------------------------------------------- */

:root {
  /* Brand */
  --color-brand: #2e7d32;
  --color-brand-dark: #1b5e20;
  --color-brand-light: #e8f5e9;

  /* Status */
  --color-error: #c62828;
  --color-error-bg: #fdecea;
  --color-success: #2e7d32;
  --color-success-bg: #e8f5e9;

  /* Neutrals */
  --color-text: #212121;
  --color-text-muted: #5f6368;
  --color-bg: #f5f5f0;
  --color-surface: #ffffff;
  --color-border: #e0e0e0;
  --color-border-strong: #c8c8c8;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Type scale */
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-h3: 1.25rem;
  --font-size-h2: 1.5rem;
  --font-size-h1: 1.875rem;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);

  /* Motion */
  --transition-fast: 120ms ease;
}

/* ---------------------------------------------------------------------
   2. Reset-ish base
   --------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: var(--space-4);
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji";
  font-size: var(--font-size-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Mobile-first centered container. Every page's body content sits inside
   this max-width so text/forms/tables stay comfortably readable on desktop
   without requiring any markup changes (Layout::render wraps every page's
   $bodyHtml directly inside <body>, so this rule targets body's own
   box — see the max-width wrapper below applied via body > * pattern is not
   reliable for a floating text node, so instead we constrain via body). */
body {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

img {
  max-width: 100%;
  height: auto;
}

/* ---------------------------------------------------------------------
   3. Headings
   --------------------------------------------------------------------- */

h1,
h2,
h3,
h4 {
  color: var(--color-text);
  font-weight: 700;
  line-height: 1.25;
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

h1:first-child,
h2:first-child,
h3:first-child {
  margin-top: 0;
}

h1 {
  font-size: var(--font-size-h1);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--color-brand);
}

h2 {
  font-size: var(--font-size-h2);
}

h3 {
  font-size: var(--font-size-h3);
}

h4 {
  font-size: var(--font-size-lg);
}

p {
  margin: 0 0 var(--space-4);
  color: var(--color-text);
}

small {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-5) 0;
}

/* ---------------------------------------------------------------------
   4. Links
   --------------------------------------------------------------------- */

a {
  color: var(--color-brand);
  text-decoration: underline;
  text-decoration-color: rgba(46, 125, 50, 0.35);
  text-underline-offset: 2px;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

a:hover {
  color: var(--color-brand-dark);
  text-decoration-color: currentColor;
}

a:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------------
   5. Top nav (admin_nav_html() and similar "back to X" link rows)
   --------------------------------------------------------------------- */

.nav {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--font-size-sm);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
}

.nav a {
  text-decoration: none;
  color: var(--color-text);
  font-weight: 600;
  white-space: nowrap;
}

.nav a:hover,
.nav a:focus-visible {
  color: var(--color-brand);
}

/* ---------------------------------------------------------------------
   6. Tables
   --------------------------------------------------------------------- */

/* Optional low-risk markup addition: wrap a <table> in
   <div class="table-scroll"> to get a horizontally-scrollable table on
   narrow viewports. Tables not wrapped still get all other table styling
   below (borders, spacing, alternating rows) — this class is additive. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-5);
}

table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-5);
  font-size: var(--font-size-sm);
}

.table-scroll table {
  margin-bottom: 0;
}

caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  padding-bottom: var(--space-2);
}

th,
td {
  padding: var(--space-3) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

th {
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background-color: #fafaf7;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background-color: var(--color-brand-light);
}

/* Since most tables in this app are not wrapped in a scroll container,
   fall back to viewport-level horizontal scroll on narrow screens so table
   content never overflows/breaks the page layout. */
@media (max-width: 600px) {
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* ---------------------------------------------------------------------
   7. Forms
   --------------------------------------------------------------------- */

form {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-card);
}

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin: 0 0 var(--space-4);
}

legend {
  font-weight: 700;
  padding: 0 var(--space-2);
}

label {
  display: block;
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  margin-bottom: var(--space-1);
  margin-top: var(--space-4);
}

label:first-child {
  margin-top: 0;
}

input,
textarea,
select {
  display: block;
  width: 100%;
  font: inherit;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  min-height: 44px; /* comfortable tap target for mobile */
  margin-bottom: var(--space-1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-block;
  width: 20px;
  height: 20px;
  min-height: 0;
  margin: 0 var(--space-2) 0 0;
  vertical-align: middle;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.18);
}

input:disabled,
textarea:disabled,
select:disabled {
  background-color: var(--color-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

input::placeholder,
textarea::placeholder {
  color: #9e9e9e;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6368' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 18px;
  padding-right: var(--space-6);
}

/* ---------------------------------------------------------------------
   8. Buttons
   --------------------------------------------------------------------- */

button,
input[type="submit"],
input[type="button"],
input[type="reset"] {
  display: inline-block;
  width: auto;
  min-height: 44px;
  margin-top: var(--space-2);
  margin-bottom: var(--space-1);
  padding: var(--space-3) var(--space-5);
  font: inherit;
  font-weight: 600;
  font-size: var(--font-size-base);
  color: #ffffff;
  background-color: var(--color-brand);
  border: 1px solid var(--color-brand);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast),
    transform var(--transition-fast);
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
  background-color: var(--color-brand-dark);
  border-color: var(--color-brand-dark);
}

button:active,
input[type="submit"]:active,
input[type="button"]:active {
  transform: translateY(1px);
}

button:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible,
input[type="reset"]:focus-visible {
  outline: 2px solid var(--color-brand-dark);
  outline-offset: 2px;
}

button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
  background-color: #a5a5a5;
  border-color: #a5a5a5;
  cursor: not-allowed;
  transform: none;
}

input[type="reset"] {
  color: var(--color-text);
  background-color: var(--color-surface);
  border-color: var(--color-border-strong);
}

input[type="reset"]:hover {
  background-color: var(--color-bg);
}

/* ---------------------------------------------------------------------
   9. Status messages (error / success notices)
   --------------------------------------------------------------------- */

.error {
  color: var(--color-error);
  background-color: var(--color-error-bg);
  border: 1px solid rgba(198, 40, 40, 0.25);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-weight: 600;
}

.notice,
.success {
  color: var(--color-success);
  background-color: var(--color-success-bg);
  border: 1px solid rgba(46, 125, 50, 0.25);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-weight: 600;
}

/* ---------------------------------------------------------------------
   10. Small utility building blocks (safe to opt into later, not required
   for the baseline retrofit to work)
   --------------------------------------------------------------------- */

.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
}

/* Promotional banner (MOD-PROMOTIONS, REQ-PROMO-03). A .card with a brand
   edge so it reads as an announcement rather than as page content. */
.banner-promo {
  border-left: 4px solid var(--color-brand-dark);
}

.banner-promo a {
  text-decoration: none;
}

/* Shared public footer nav (MOD-CONTENT-PUBLIC), rendered on every page by
   Support\Layout. */
.site-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  line-height: 1.9;
}

/* ---------------------------------------------------------------------
   11. Mobile viewport comfort
   --------------------------------------------------------------------- */

@media (max-width: 480px) {
  body {
    padding: var(--space-3);
  }

  form {
    padding: var(--space-4);
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }
}
