/* ==========================================================================
   BersihBG Design System — token-driven, built on DESIGN.md (remove.bg spec)
   Brand accent: teal. Foundations: typography/spacing/radius/shadow/motion.
   Accessibility: WCAG 2.2 AA, focus-visible, reduced-motion.
   ========================================================================== */

:root {
  /* ---- Color tokens ---- */
  --color-brand:            #0d9488; /* teal primary (BersihBG identity) */
  --color-brand-hover:      #0f766e;
  --color-brand-active:     #115e59;
  --color-brand-tint:       #e6f4f2;
  --color-brand-secondary:  #0ea5e9; /* sky accent */

  --color-text-primary:     #454545;
  --color-text-secondary:   #54616c;
  --color-text-tertiary:    #8a949e;
  --color-text-inverse:     #ffffff;

  --color-surface-base:     #ffffff;
  --color-surface-raised:   #edf0f2;
  --color-surface-sunken:   #f7f9fa;
  --color-surface-ink:      #0f1518; /* near-black for footers/dark */

  --color-border:           #dbe1e5;
  --color-border-strong:    #c3ccd2;

  --color-success:          #16a34a;
  --color-warning:          #d97706;
  --color-error:            #dc2626;
  --color-error-tint:       #fdecec;

  --color-focus-ring:       #0ea5e9;

  /* ---- Typography ---- */
  --font-family: "Open Sans", "Canva Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;
  --fs-4xl: 48px;
  --lh-base: 24px;
  --fw-regular: 400;
  --fw-medium: 600;
  --fw-bold: 700;

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

  /* ---- Radius ---- */
  --radius-xs: 4px;
  --radius-sm: 16px;
  --radius-pill: 9999px;

  /* ---- Shadow ---- */
  --shadow-1: rgba(14, 19, 24, 0.07) 0px 0px 4px 0px;
  --shadow-2: 0 4px 12px rgba(14, 19, 24, 0.10);
  --shadow-3: 0 12px 28px rgba(14, 19, 24, 0.14);

  /* ---- Motion ---- */
  --motion-instant: 150ms;
  --motion-fast: 200ms;
  --motion-normal: 300ms;
  --motion-slow: 500ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --container-max: 1200px;
  --nav-h: 64px;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-family);
  font-size: var(--fs-lg);
  line-height: var(--lh-base);
  font-weight: var(--fw-regular);
  color: var(--color-text-primary);
  background: var(--color-surface-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg, video { display: block; max-width: 100%; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
ul { list-style: none; padding: 0; }

h1, h2, h3, h4 { line-height: 1.2; color: var(--color-text-primary); font-weight: var(--fw-bold); }
h1 { font-size: var(--fs-4xl); letter-spacing: -0.02em; }
h2 { font-size: var(--fs-3xl); letter-spacing: -0.01em; }
h3 { font-size: var(--fs-2xl); font-weight: var(--fw-medium); }
h4 { font-size: var(--fs-xl); font-weight: var(--fw-medium); }
@media (max-width: 768px) {
  h1 { font-size: var(--fs-3xl); }
  h2 { font-size: var(--fs-2xl); }
}

/* ==========================================================================
   Accessibility — focus-visible & reduced motion
   ========================================================================== */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 200;
  background: var(--color-brand); color: #fff; padding: 10px 16px; border-radius: var(--radius-xs);
}
.skip-link:focus { left: 8px; }

/* ==========================================================================
   Layout helpers
   ========================================================================== */
.container { width: 100%; max-width: var(--container-max); margin-inline: auto; padding-inline: var(--space-5); }
.section { padding-block: var(--space-8); }
.section--sm { padding-block: var(--space-7); }
.stack > * + * { margin-top: var(--space-5); }
.text-center { text-align: center; }
.muted { color: var(--color-text-secondary); }
.eyebrow { color: var(--color-brand); font-weight: var(--fw-bold); font-size: var(--fs-md); letter-spacing: 0.04em; text-transform: uppercase; }
.lead { font-size: var(--fs-xl); color: var(--color-text-secondary); line-height: 1.5; }
.grid { display: grid; gap: var(--space-6); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px) { .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; } }

/* ==========================================================================
   Buttons — states: default, hover, focus-visible, active, disabled, loading
   ========================================================================== */
.btn {
  --btn-bg: var(--color-brand);
  --btn-fg: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-size: var(--fs-md); font-weight: var(--fw-medium); line-height: 1;
  padding: 12px 20px; border-radius: var(--radius-xs); border: 2px solid transparent;
  background: var(--btn-bg); color: var(--btn-fg); cursor: pointer;
  transition: background var(--motion-fast) var(--ease), transform var(--motion-instant) var(--ease), box-shadow var(--motion-fast) var(--ease);
  text-align: center; white-space: nowrap;
}
.btn:hover { background: var(--color-brand-hover); }
.btn:active { background: var(--color-brand-active); transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn--secondary { --btn-bg: transparent; --btn-fg: var(--color-brand); border-color: var(--color-brand); }
.btn--secondary:hover { --btn-bg: var(--color-brand-tint); background: var(--color-brand-tint); }
.btn--secondary:active { background: var(--color-brand-tint); }
.btn--ghost { --btn-bg: transparent; --btn-fg: var(--color-text-primary); }
.btn--ghost:hover { background: var(--color-surface-raised); }
.btn--on-brand { --btn-bg: #fff; --btn-fg: var(--color-brand); }
.btn--on-brand:hover { background: var(--color-surface-raised); }
.btn--lg { padding: 15px 28px; font-size: var(--fs-lg); }
.btn--sm { padding: 8px 14px; font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn--pill { border-radius: var(--radius-pill); }
.btn.is-loading { color: transparent; position: relative; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; color: var(--btn-fg);
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Forms — inputs with default/focus/disabled/error states
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--color-text-primary); }
.input, .textarea, .select {
  width: 100%; padding: 11px 14px; font-size: var(--fs-lg);
  background: var(--color-surface-base); color: var(--color-text-primary);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-xs);
  transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--color-text-tertiary); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--color-text-tertiary); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: none; border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}
.input:disabled { background: var(--color-surface-raised); cursor: not-allowed; opacity: 0.7; }
.field.has-error .input { border-color: var(--color-error); }
.field .error-text { color: var(--color-error); font-size: var(--fs-sm); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .input-affix {
  position: absolute; right: 8px; background: none; border: 0; cursor: pointer;
  color: var(--color-text-tertiary); padding: 6px; border-radius: var(--radius-xs); display: inline-flex;
}
.input-wrap .input-affix:hover { color: var(--color-text-primary); }
.checkbox { display: inline-flex; align-items: flex-start; gap: var(--space-2); font-size: var(--fs-md); color: var(--color-text-secondary); }
.checkbox input { width: 18px; height: 18px; accent-color: var(--color-brand); margin-top: 1px; }

/* ==========================================================================
   Cards / surfaces
   ========================================================================== */
.card {
  background: var(--color-surface-base); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: var(--space-6); box-shadow: var(--shadow-1);
}
.card--interactive { transition: box-shadow var(--motion-fast) var(--ease), transform var(--motion-fast) var(--ease); }
.card--interactive:hover { box-shadow: var(--shadow-2); transform: translateY(-3px); }
.card--raised { background: var(--color-surface-raised); border-color: transparent; }

/* ==========================================================================
   Badges / chips
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--color-surface-raised); color: var(--color-text-secondary);
}
.badge--free { background: var(--color-surface-raised); color: var(--color-text-secondary); }
.badge--vip { background: var(--color-brand-tint); color: var(--color-brand-hover); }
.badge--new { background: #e0f2fe; color: #0369a1; }
.chip {
  display: inline-flex; align-items: center; font-size: var(--fs-sm); padding: 6px 12px;
  border-radius: var(--radius-pill); border: 1px solid var(--color-border); color: var(--color-text-secondary);
  background: var(--color-surface-base);
}

/* ==========================================================================
   Navigation (top bar)
   ========================================================================== */
.nav {
  position: sticky; top: 0; z-index: 100; background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(1.2) blur(8px); border-bottom: 1px solid var(--color-border);
}
.nav__inner { display: flex; align-items: center; justify-content: space-between; height: var(--nav-h); }
.brand { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-2xl); font-weight: var(--fw-bold); color: var(--color-brand); }
.brand__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-brand-secondary); }
.nav__links { display: flex; align-items: center; gap: var(--space-6); }
.nav__link { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--color-text-secondary); padding: 6px 2px; border-bottom: 2px solid transparent; transition: color var(--motion-fast) var(--ease); }
.nav__link:hover { color: var(--color-brand); }
.nav__link--active { color: var(--color-brand); border-bottom-color: var(--color-brand); }
.nav__actions { display: flex; align-items: center; gap: var(--space-3); }
.nav__toggle { display: none; background: none; border: 0; cursor: pointer; padding: 8px; color: var(--color-text-primary); }
@media (max-width: 860px) {
  .nav__links { display: none; }
  .nav__actions .btn, .nav__actions .nav__link { display: none; }
  .nav__toggle { display: inline-flex; }
  .nav__links.is-open {
    display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-4);
    position: absolute; top: var(--nav-h); left: 0; right: 0; background: #fff;
    padding: var(--space-5); border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow-2);
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer { background: var(--color-surface-ink); color: #cbd3d8; padding-block: var(--space-8) var(--space-6); }
.footer a { color: #cbd3d8; }
.footer a:hover { color: #fff; }
.footer__grid { display: grid; grid-template-columns: 1.5fr repeat(3, 1fr); gap: var(--space-6); }
@media (max-width: 780px) { .footer__grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .footer__grid { grid-template-columns: 1fr; } }
.footer__brand { color: #fff; font-size: var(--fs-2xl); font-weight: var(--fw-bold); }
.footer__title { color: #fff; font-size: var(--fs-md); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: var(--space-3); }
.footer__links { display: flex; flex-direction: column; gap: var(--space-3); font-size: var(--fs-md); }
.footer__bottom { border-top: 1px solid rgba(255,255,255,0.1); margin-top: var(--space-7); padding-top: var(--space-5); display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); font-size: var(--fs-sm); color: #8a949e; }

/* ==========================================================================
   Hero / marketing bits
   ========================================================================== */
.hero { padding-block: var(--space-8); }
.hero__grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: var(--space-8); align-items: center; }
@media (max-width: 900px) { .hero__grid { grid-template-columns: 1fr; text-align: center; } }
.dropzone { border: 2px dashed var(--color-brand); background: var(--color-brand-tint); border-radius: var(--radius-sm); padding: var(--space-8) var(--space-6); text-align: center; }
.icon-badge { width: 48px; height: 48px; border-radius: var(--radius-xs); background: var(--color-brand-tint); color: var(--color-brand); display: inline-flex; align-items: center; justify-content: center; }
.material-symbols-outlined { font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.filled { font-variation-settings: 'FILL' 1; }

/* Pricing */
.price { font-size: var(--fs-4xl); font-weight: var(--fw-bold); color: var(--color-text-primary); }
.price small { font-size: var(--fs-md); font-weight: var(--fw-regular); color: var(--color-text-secondary); }
.plan--featured { border: 2px solid var(--color-brand); position: relative; }
.check-list { display: flex; flex-direction: column; gap: var(--space-3); text-align: left; }
.check-list li { display: flex; gap: var(--space-2); align-items: center; color: var(--color-text-secondary); font-size: var(--fs-md); }
.check-list .material-symbols-outlined { color: var(--color-brand); font-size: 20px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
table.data th, table.data td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--color-border); }
table.data th { background: var(--color-surface-sunken); font-weight: var(--fw-bold); color: var(--color-text-secondary); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.03em; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--color-surface-sunken); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--color-surface-ink); color: #fff; padding: 12px 20px; border-radius: var(--radius-xs);
  font-size: var(--fs-md); z-index: 9999; box-shadow: var(--shadow-3); opacity: 0;
  transition: opacity var(--motion-normal) var(--ease), transform var(--motion-normal) var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--success { background: #0d9488; }
.toast--error { background: #dc2626; }
.toast--info { background: #2563eb; }

/* Offline banner */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10000;
  background: #b45309; color: #fff; text-align: center;
  padding: 8px 16px; font-size: var(--fs-md);
  transform: translateY(-100%); transition: transform var(--motion-normal) var(--ease);
}
.offline-banner.show { transform: translateY(0); }

/* Auth layout */
.auth { min-height: calc(100vh - var(--nav-h)); display: grid; place-items: center; padding: var(--space-7) var(--space-5); background: var(--color-surface-sunken); }
.auth__card { width: 100%; max-width: 440px; }
.divider { display: flex; align-items: center; gap: var(--space-3); color: var(--color-text-tertiary); font-size: var(--fs-sm); }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--color-border); flex: 1; }

/* Dashboard shell */
.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--color-border); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); position: sticky; top: 0; height: 100vh; }
.side-link { display: flex; align-items: center; gap: var(--space-3); padding: 10px 12px; border-radius: var(--radius-xs); color: var(--color-text-secondary); font-weight: var(--fw-medium); font-size: var(--fs-md); }
.side-link:hover { background: var(--color-surface-raised); color: var(--color-text-primary); }
.side-link--active { background: var(--color-brand-tint); color: var(--color-brand-hover); }
.app__main { display: flex; flex-direction: column; min-width: 0; }
.app__header { height: var(--nav-h); border-bottom: 1px solid var(--color-border); background: #fff; display: flex; align-items: center; justify-content: space-between; padding-inline: var(--space-6); position: sticky; top: 0; z-index: 40; }
.progress { height: 8px; background: var(--color-surface-raised); border-radius: var(--radius-pill); overflow: hidden; }
.progress__bar { height: 100%; background: var(--color-brand); border-radius: var(--radius-pill); transition: width var(--motion-slow) var(--ease); }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 120; width: 256px; transform: translateX(-100%); transition: transform var(--motion-normal) var(--ease); }
  .sidebar.is-open { transform: translateX(0); }
}
.overlay { position: fixed; inset: 0; background: rgba(15,21,24,0.5); z-index: 110; }
.overlay[hidden] { display: none; }

/* App-shell + admin mobile menu toggle button */
.app__header .nav__toggle,
.admin-menu { display: none; }

@media (max-width: 860px) {
  .app__header .nav__toggle,
  .admin-menu { display: inline-flex; }
}

/* ==========================================================================
   Drop zone (file upload)
   ========================================================================== */
#dropZone {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
/* ── Quality selector (shared) ── */
.q-select{display:flex;flex-direction:column;gap:var(--space-2);}
.q-select__label{font-size:var(--fs-md);font-weight:600;}
.q-seg{display:flex;gap:var(--space-2);flex-wrap:wrap;}
.q-seg__btn{display:inline-flex;align-items:center;gap:4px;padding:var(--space-2) var(--space-4);border:1px solid var(--color-border);border-radius:var(--radius-xs);background:#fff;cursor:pointer;font-weight:600;font:inherit;transition:border-color .15s,color .15s,background .15s;}
.q-seg__btn:hover{border-color:var(--color-brand);}
.q-seg__btn.active{border-color:var(--color-brand);color:var(--color-brand);background:var(--color-surface-sunken);}
.q-seg__btn .q-lock{font-size:15px;vertical-align:-2px;opacity:.7;}
/* Shared upgrade modal */
.q-modal{position:fixed;inset:0;z-index:1000;display:none;align-items:center;justify-content:center;padding:var(--space-4);}
.q-modal.is-open{display:flex;}
.q-modal__backdrop{position:absolute;inset:0;background:rgba(0,0,0,.5);}
.q-modal__panel{position:relative;background:#fff;border-radius:var(--radius-sm);padding:var(--space-6);max-width:400px;width:100%;text-align:center;box-shadow:0 12px 40px rgba(0,0,0,.25);}
.q-modal__close{position:absolute;top:8px;right:8px;background:none;border:none;cursor:pointer;color:var(--color-text-tertiary);display:grid;place-items:center;padding:4px;}

/* ---- Dark mode ---- */
[data-theme="dark"] {
  --color-brand:            #2dd4bf;
  --color-brand-hover:      #5eead4;
  --color-brand-active:     #99f6e4;
  --color-brand-tint:       #134e4a;
  --color-brand-secondary:  #38bdf8;

  --color-text-primary:     #e6eaed;
  --color-text-secondary:   #aeb8c0;
  --color-text-tertiary:    #7c868f;
  --color-text-inverse:     #0f1518;

  --color-surface-base:     #0f1518;
  --color-surface-raised:   #1b242a;
  --color-surface-sunken:   #151d22;
  --color-surface-ink:      #060a0c;

  --color-border:           #2a353c;
  --color-border-strong:    #3a4750;

  --color-success:          #22c55e;
  --color-warning:          #f59e0b;
  --color-error:            #f87171;
  --color-error-tint:       #3a1f1f;

  --color-focus-ring:       #38bdf8;

  --shadow-1: rgba(0,0,0,0.45) 0px 0px 4px 0px;
  --shadow-2: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-3: 0 12px 28px rgba(0,0,0,0.6);
}
/* Component surfaces that were hardcoded light */
[data-theme="dark"] .nav { background: rgba(15,21,24,0.92); }
[data-theme="dark"] .nav__links { background: var(--color-surface-raised); }
[data-theme="dark"] .sidebar,
[data-theme="dark"] .app__header { background: var(--color-surface-raised); }
[data-theme="dark"] .q-seg__btn { background: var(--color-surface-raised); color: var(--color-text-primary); }
[data-theme="dark"] .q-modal__panel { background: var(--color-surface-raised); color: var(--color-text-primary); }

/* Smooth theme transition */
body, .nav, .sidebar, .app__header, .card, .footer { transition: background-color .25s ease, border-color .25s ease, color .25s ease; }

/* Theme toggle button */
.theme-toggle { background:none; border:none; cursor:pointer; color:var(--color-text-secondary); display:inline-flex; align-items:center; gap:8px; padding:6px; border-radius:var(--radius-xs); transition:color .15s, background .15s; }
.theme-toggle:hover { color:var(--color-brand); background:var(--color-surface-raised); }
.theme-toggle .material-symbols-outlined { font-size:22px; }
.theme-toggle--sidebar { width:100%; justify-content:flex-start; padding:10px 12px; font:inherit; font-weight:600; color:var(--color-text-secondary); margin-top:12px; }
.theme-toggle--sidebar:hover { color:var(--color-brand); }
