/* patamal.css — single hand-written design system. No bundler, no CDN.
   Theming via :root custom properties; per-store/branding overrides inject a
   small <style> block overriding --brand-* tokens. */

:root {
  /* Brand tokens — overridable at runtime from the system-admin branding
     settings (task: branding). These are the seed defaults. */
  --brand-primary: #0f766e;   /* teal */
  --brand-primary-600: #0d655e;
  --brand-accent: #f59e0b;    /* amber */

  /* Surfaces & text (light theme default). */
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e3e3df;
  --text: #1b1b1a;
  --text-muted: #6b6b66;
  --danger: #d64545;
  --success: #2f9e6f;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --container: 1140px;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #121311;
  --surface: #1b1d1a;
  --surface-2: #232622;
  --border: #2f332e;
  --text: #ececea;
  --text-muted: #9a9a93;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

.lang-si { --font: 'Noto Sans Sinhala', system-ui, sans-serif; }
.lang-ta { --font: 'Noto Sans Tamil', system-ui, sans-serif; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.site-main { flex: 1 0 auto; width: 100%; }
.container { max-width: var(--container); margin: 0 auto; padding: 0 20px; }
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.link { color: var(--brand-primary); font-weight: 500; }
.inline { display: inline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .55em 1.1em; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { background: var(--brand-primary-600); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { padding: .5em .7em; }
.btn-lg { padding: .75em 1.5em; font-size: 1.05rem; }
.badge {
  background: var(--brand-accent); color: #1b1b1a; font-size: .7rem; font-weight: 700;
  border-radius: 999px; padding: .1em .5em; margin-left: .15em;
}

/* Top nav */
.topnav { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topnav-inner { display: flex; align-items: center; gap: 18px; height: 64px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); font-weight: 700; font-size: 1.2rem; }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; }
.topnav-search { flex: 1; display: flex; max-width: 560px; }
.topnav-search input {
  flex: 1; font: inherit; padding: .55em .9em; border: 1px solid var(--border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--bg); color: var(--text);
}
.topnav-search .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--brand-primary); color: #fff; }
.topnav-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.navlink { color: var(--text); font-weight: 500; }
.lang-switch { display: inline-flex; gap: 6px; font-size: .85rem; }
.lang-switch a { color: var(--text-muted); }
.lang-switch a.active { color: var(--brand-primary); font-weight: 700; }

/* Hero */
.hero { padding: 56px 20px 32px; }
.hero-copy { max-width: 640px; }
.hero h1 { font-size: 2.4rem; }
.lead { font-size: 1.15rem; color: var(--text-muted); }
.hero-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* Sections */
.section { padding: 24px 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 1.4rem; }

/* Category chips */
.category-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.category-chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: .5em 1em; border-radius: 999px; font-weight: 500;
}
.category-chip:hover { border-color: var(--brand-primary); text-decoration: none; }

/* Product grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); display: flex; flex-direction: column; }
.product-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.product-card-media { aspect-ratio: 1/1; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.product-card-media img { width: 100%; height: 100%; object-fit: cover; }
.product-card-noimg { color: var(--text-muted); font-size: .85rem; }
.product-card-body { padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.product-card-name { font-size: .98rem; margin: 0; }
.product-card-price { font-weight: 700; color: var(--brand-primary); }

/* Empty states */
.empty-state { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 40px; text-align: center; }
.empty-note { padding: 12px 0; }
.search-hl { background: var(--brand-accent); color: #1b1b1a; border-radius: 2px; }

/* Footer */
.site-footer { flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border); margin-top: 40px; }
.site-footer-inner { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; justify-content: space-between; padding-top: 28px; padding-bottom: 28px; }
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-links a { color: var(--text-muted); }

/* Toasts */
.toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--brand-primary); border-radius: var(--radius-sm); padding: .7em 1em; box-shadow: var(--shadow); max-width: 320px; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* Narrow content column + wide form */
.narrow { max-width: 680px; }
.form.wide { max-width: none; }
.slug-input { display: flex; align-items: stretch; }
.slug-prefix { display: flex; align-items: center; padding: 0 .6em; background: var(--surface-2); border: 1px solid var(--border); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--text-muted); font-size: .9rem; }
.slug-input input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; flex: 1; }

/* Store header (storefront) */
.store-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.store-header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 28px 20px; }
.store-identity { display: flex; align-items: center; gap: 16px; }
.store-logo { width: 64px; height: 64px; border-radius: var(--radius); object-fit: cover; }

/* Seller portal */
.manage-head { margin-bottom: 22px; }
.manage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.manage-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; color: var(--text); }
.manage-card:hover { box-shadow: var(--shadow); text-decoration: none; border-color: var(--brand-primary); }
.manage-card h3 { margin: 0 0 .3em; }

/* Sysadmin request queue */
.request-list { display: flex; flex-direction: column; gap: 14px; }
.request-card { display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.request-main { flex: 1; min-width: 260px; }
.request-main h3 { margin: 0 0 .2em; }
.request-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; min-width: 180px; }
.reject-form { display: flex; gap: 6px; }
.reject-form input { flex: 1; font: inherit; padding: .45em .6em; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }

/* Data tables (portal) */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.data-table tr:last-child td { border-bottom: 0; }
.td-thumb img, .thumb-empty { width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); display: block; }
.td-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.btn-sm { padding: .35em .7em; font-size: .85rem; }
.pill { display: inline-block; padding: .15em .6em; border-radius: 999px; font-size: .78rem; background: var(--surface-2); color: var(--text-muted); }
.pill-ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }

/* Form helpers */
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.field-check label { font-weight: 400; display: flex; align-items: center; gap: 8px; }

/* Product images (portal) */
.image-grid { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.image-tile { width: 120px; }
.image-tile img { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; margin-bottom: 6px; }
.add-image { display: flex; gap: 8px; align-items: center; }

/* Category chip active + pager */
.category-chip.is-active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 28px; }

/* Product detail */
.product-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: start; }
.gallery-main { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.gallery-empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gallery-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.product-info h1 { font-size: 1.8rem; }
.product-price { font-size: 1.6rem; font-weight: 700; color: var(--brand-primary); margin: 12px 0; }
.stock { font-weight: 600; }
.stock.in { color: var(--success); }
.stock.out { color: var(--danger); }
.add-to-cart { display: flex; gap: 10px; align-items: center; margin: 16px 0; }
.add-to-cart input[type=number] { width: 72px; font: inherit; padding: .6em; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.product-desc { margin-top: 18px; white-space: pre-wrap; line-height: 1.6; }
@media (max-width: 760px) { .product-detail { grid-template-columns: 1fr; } }

/* Cart */
.cart-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.cart-group-head { margin: 0 0 10px; font-size: 1.05rem; }
.cart-line { display: grid; grid-template-columns: 56px 1fr auto auto auto; gap: 14px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.cart-line-img img, .cart-line-img .thumb-empty { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); }
.cart-line-info a { font-weight: 600; }
.cart-line-issue { opacity: .7; }
.cart-qty { display: flex; gap: 6px; align-items: center; }
.cart-qty input { width: 64px; font: inherit; padding: .4em; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); }
.cart-line-total { font-weight: 700; min-width: 90px; text-align: right; }
.cart-subtotal { text-align: right; padding-top: 10px; border-top: 1px solid var(--border); margin-top: 8px; }
.cart-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.cart-grand { font-size: 1.2rem; }
@media (max-width: 640px) { .cart-line { grid-template-columns: 48px 1fr; } .cart-line-total { text-align: left; } }

/* Checkout */
.checkout { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
.checkout-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.checkout-block h2 { font-size: 1.1rem; margin-top: 0; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; }
.radio-inline { display: inline-flex; gap: 6px; align-items: center; margin-right: 16px; }
.new-address { margin-top: 10px; }
.checkout-items { list-style: none; padding: 0; margin: 0 0 10px; }
.checkout-items li { padding: 3px 0; display: flex; justify-content: space-between; }
.checkout-pay { padding: 10px 0; border-top: 1px solid var(--border); }
.checkout-subtotal { text-align: right; padding-top: 8px; }
.checkout-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: sticky; top: 80px; }
@media (max-width: 820px) { .checkout { grid-template-columns: 1fr; } .checkout-summary { position: static; } }

/* Cards + order detail */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h3 { margin-top: 0; }
.order-item { padding: 4px 0; display: flex; justify-content: space-between; }
.order-total { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; text-align: right; }
.address-card { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.bank-fields { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin: 12px 0; }
.bank-fields legend { padding: 0 6px; color: var(--text-muted); font-size: .9rem; }

/* Order timeline */
.timeline { list-style: none; display: flex; flex-wrap: wrap; gap: 0; padding: 0; margin: 16px 0; counter-reset: step; }
.timeline li { flex: 1; min-width: 90px; text-align: center; position: relative; padding-top: 24px; color: var(--text-muted); font-size: .85rem; }
.timeline li::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--border); position: absolute; top: 0; left: 50%; transform: translateX(-50%); }
.timeline li::after { content: ""; position: absolute; top: 6px; left: 0; right: 50%; height: 2px; background: var(--border); }
.timeline li:first-child::after { display: none; }
.timeline li.done, .timeline li.current { color: var(--text); }
.timeline li.done::before, .timeline li.current::before { background: var(--brand-primary); border-color: var(--brand-primary); }
.timeline li.done::after, .timeline li.current::after { background: var(--brand-primary); }

/* System admin */
.sysnav { display: flex; flex-wrap: wrap; gap: 4px; margin: 16px 0 24px; border-bottom: 1px solid var(--border); }
.sysnav a { padding: 8px 14px; color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 500; }
.sysnav a:hover { color: var(--text); text-decoration: none; }
.sysnav a.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--brand-primary); }

/* Auth pages */
.auth-page { display: flex; justify-content: center; padding: 48px 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: .2em; }
.auth-card .form { max-width: none; margin-top: 18px; }
.auth-alt { margin-top: 18px; text-align: center; }

/* Forms (shared) */
.form { max-width: 420px; margin: 0 auto; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 600; font-size: .9rem; }
.field input, .field select, .field textarea {
  font: inherit; padding: .6em .8em; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.form-error { background: #fdecec; color: var(--danger); border: 1px solid #f3c4c4; border-radius: var(--radius-sm); padding: .7em 1em; margin-bottom: 14px; }
[data-theme="dark"] .form-error { background: #3a1d1d; border-color: #5a2a2a; }

@media (max-width: 720px) {
  .topnav-search { display: none; }
  .hero h1 { font-size: 1.9rem; }
}
