/* ============================================================
   Lakuhan UI: shared pieces, one look on every page.

   Link it right AFTER /assets/ds/styles.css (the design-system tokens:
   --kp-*, --slate-*, --r-*, --sp-*, --fs-*, --shadow-*) and BEFORE the
   page's own CSS, so page rules still win:
     <link rel="stylesheet" href="/assets/ui.css?v=2">

   Nothing here styles a bare element; every rule needs a class, so
   linking the file alone changes nothing on a page.

   Pieces (class: what it is)
     .btn                 button or link that looks like one (pair it with a kind)
       .btn-primary       forest, white text (main action)
       .btn-secondary     white, bordered (also .btn-outline)
       .btn-danger        solid red (destructive confirm)
       .btn-danger-ghost  white, red text and border (destructive, not final)
       .btn-sm            small, for dense rows
       .btn-block         full width
     .textbtn             quiet text button: underlined, no box
     .form-field          wraps one label + control + hint/error (add .is-invalid)
       .form-label  .form-hint  .form-error
     .input               text input, select or textarea (aria-invalid="true" turns it red)
     .card                white panel with a hairline and soft shadow
     .tag                 small pill; kinds .tag-brand .tag-success .tag-info
                          .tag-warning .tag-danger (default is neutral)
     .notice              tinted box with a message; kinds .notice-info
                          .notice-success .notice-warning .notice-error
     .table               simple data table (th = small grey caps, rows ruled)
     .dialog              <dialog> panel (its ::backdrop is dimmed); .dialog-actions row
   Focus: the ring comes from ds/base/focus.css (2px forest, 2px offset);
   .btn, .textbtn and .input restore it where a page removed outlines.
   Dark: tokens below switch inside .kp-night (the dashboard's night mode).
   ============================================================ */

:root {
  --ui-accent: var(--kp-pink, #233d31);          /* forest */
  --ui-accent-hover: var(--kp-pink-deep, #1b3026);
  --ui-ink: var(--kp-ink, #222923);
  --ui-text: var(--slate-700, #334155);
  --ui-muted: var(--slate-600, #475569);
  --ui-surface: #fff;
  --ui-sunken: #f3f6ee;                           /* soft forest tint */
  --ui-line: var(--kp-line, rgba(34, 41, 35, .10));
  --ui-line-strong: var(--kp-line-strong, rgba(34, 41, 35, .18));
  --ui-row-line: var(--slate-100, #f1f5f9);
  --ui-focus: var(--accent-strong, #1b3026);
  --ui-glow: 0 0 0 3px rgba(35, 61, 49, .15);     /* input focus halo */
  --ui-shadow-card: var(--shadow-card, 0 1px 2px rgba(34, 41, 35, .04), 0 12px 32px -18px rgba(34, 41, 35, .22));
  --ui-shadow-dialog: 0 24px 60px rgba(0, 0, 0, .32);
  --ui-backdrop: rgba(15, 23, 42, .55);

  --ui-r-sm: 8px;     /* small buttons */
  --ui-r: 10px;       /* buttons, inputs */
  --ui-r-box: 12px;   /* notices */
  --ui-r-card: 14px;  /* cards, dialogs */
  --ui-r-pill: 999px; /* tags */

  --ui-danger: var(--kp-danger, #dc2626);
  --ui-danger-text: #b91c1c;
  --ui-danger-line: #fecaca;
  --ui-danger-soft: #fef2f2;

  /* notice / tag tints: bg, border, text */
  --ui-info-bg: #f3f6ee;     --ui-info-line: var(--kp-line-strong, rgba(34, 41, 35, .18)); --ui-info-text: var(--kp-ink, #222923);
  --ui-success-bg: #f0fdf4;  --ui-success-line: #bbf7d0; --ui-success-text: #166534;
  --ui-warning-bg: #fffbeb;  --ui-warning-line: #fde68a; --ui-warning-text: #92400e;
  --ui-error-bg: #fef2f2;    --ui-error-line: #fecaca;   --ui-error-text: #991b1b;
}

/* The dashboard's night mode (#dashboard.kp-night) and shared dark pages (html[data-theme="dark"]). */
.kp-night,
html[data-theme="dark"] {
  --ui-ink: #f4f7f2;
  --ui-text: #d7e2db;
  --ui-muted: #b0c2b6;
  --ui-surface: #141c18;
  --ui-sunken: #0f1612;
  --ui-line: #293a31;
  --ui-line-strong: #466052;
  --ui-row-line: #1f2d26;
  --ui-accent: #1d4d35;
  --ui-accent-hover: #245f42;
  --ui-focus: #d8f68b;
  --ui-danger-text: #fca5a5; --ui-danger-line: #7f1d1d; --ui-danger-soft: #2a1214;
  --ui-info-bg: #17231d;     --ui-info-line: #2d4337;   --ui-info-text: #f4f7f2;
  --ui-success-bg: #0f2a1c;  --ui-success-line: #1f5135; --ui-success-text: #86efac;
  --ui-warning-bg: #2e200d;  --ui-warning-line: #6b4e1e; --ui-warning-text: #fde68a;
  --ui-error-bg: #2a1214;    --ui-error-line: #7f1d1d;   --ui-error-text: #fca5a5;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 11px 16px; border: 1px solid transparent; border-radius: var(--ui-r);
  font-family: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  /* shortcut: no font-size, line-height or transition here: pages still differ (app 13px,
     admin 14px, pay 1rem, purchases 14px). Add one once they agree. */
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .6; cursor: not-allowed; }
.btn:focus-visible, .textbtn:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.btn-primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--ui-accent-hover); border-color: var(--ui-accent-hover); }
.btn-secondary, .btn-outline { background: var(--ui-surface); border-color: var(--ui-line-strong); color: var(--ui-ink); }
.btn-secondary:hover:not(:disabled), .btn-outline:hover:not(:disabled) { border-color: var(--ui-accent); color: var(--ui-accent-hover); }
.btn-danger { background: var(--ui-danger); border-color: var(--ui-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }
.btn-danger-ghost { background: var(--ui-surface); border-color: var(--ui-danger-line); color: var(--ui-danger-text); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--ui-danger-soft); border-color: #fca5a5; }
.btn-sm { min-height: 44px; padding: 7px 14px; font-size: 12px; border-radius: var(--ui-r-sm); }
.btn-block { width: 100%; }

.textbtn {
  padding: 0; border: 0; background: none; min-height: 44px; display: inline-flex; align-items: center;
  font: inherit; font-weight: 700; color: var(--ui-accent);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.textbtn:hover { color: var(--ui-accent-hover); }
.kp-night .textbtn, html[data-theme="dark"] .textbtn { color: #9ce6ba; }
.kp-night .textbtn:hover, html[data-theme="dark"] .textbtn:hover { color: #d8f68b; }
.kp-night .btn-secondary:hover:not(:disabled),
.kp-night .btn-outline:hover:not(:disabled),
html[data-theme="dark"] .btn-secondary:hover:not(:disabled),
html[data-theme="dark"] .btn-outline:hover:not(:disabled) { border-color: #6fb28b; color: #f4f7f2; }

/* ---- Forms ---- */
.form-field { display: grid; gap: 6px; margin-bottom: 16px; min-width: 0; }
.form-label { font-size: 12px; font-weight: 600; color: var(--ui-muted); }
.form-hint { font-size: 12px; line-height: 1.4; color: var(--kp-mute-2, #566058); }
.form-error { font-size: 12px; line-height: 1.4; font-weight: 600; color: var(--ui-danger-text); }
.form-error:empty { display: none; }

.input {
  box-sizing: border-box; width: 100%; max-width: 100%; min-height: 44px;
  padding: 10px 12px; border: 1px solid var(--ui-line-strong); border-radius: var(--ui-r);
  background: var(--ui-surface); color: var(--ui-ink);
  font: inherit; font-size: 14px; line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 76px; resize: vertical; }
.input::placeholder { color: var(--kp-mute-4, #6d776f); }
.input:hover:not(:focus):not(:disabled) { border-color: var(--slate-400, #94a3b8); }
.input:focus { border-color: var(--ui-accent); box-shadow: var(--ui-glow); }
.input:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.input:disabled { opacity: .6; cursor: not-allowed; }
.input[aria-invalid="true"], .form-field.is-invalid .input { border-color: var(--ui-danger); }
.input[aria-invalid="true"]:focus, .form-field.is-invalid .input:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .15); }

/* ---- Card ---- */
.card {
  padding: 20px; background: var(--ui-surface); color: var(--ui-ink);
  border: 1px solid var(--ui-line); border-radius: var(--ui-r-card);
  box-shadow: var(--ui-shadow-card);
}

/* ---- Tag (pill) ---- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--ui-r-pill);
  background: var(--slate-100, #f1f5f9); color: var(--ui-muted);
  font-size: 12px; font-weight: 700; line-height: 1.3;
}
.tag-brand { background: var(--ui-sunken); color: var(--ui-accent-hover); }
.tag-success { background: var(--ui-success-bg); color: var(--ui-success-text); }
.tag-info { background: var(--kp-info-bg, #dbeafe); color: var(--kp-info-text, #1e40af); }
.tag-warning { background: var(--kp-warning-bg, #fef3c7); color: var(--ui-warning-text); }
.tag-danger { background: var(--kp-danger-bg, #fee2e2); color: var(--ui-danger-text); }

/* ---- Notice ---- */
.notice {
  padding: 12px 14px; border: 1px solid var(--ui-info-line); border-radius: var(--ui-r-box);
  background: var(--ui-info-bg); color: var(--ui-info-text);
  font-size: 13px; line-height: 1.5;
}
.notice > :first-child { margin-top: 0; }
.notice > :last-child { margin-bottom: 0; }
.notice-success { background: var(--ui-success-bg); border-color: var(--ui-success-line); color: var(--ui-success-text); }
.notice-warning { background: var(--ui-warning-bg); border-color: var(--ui-warning-line); color: var(--ui-warning-text); }
.notice-error { background: var(--ui-error-bg); border-color: var(--ui-error-line); color: var(--ui-error-text); }

/* ---- Table ---- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; color: var(--ui-text); }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--ui-row-line); }
.table th {
  font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: var(--ui-muted); border-bottom-color: var(--ui-line);
}
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.kp-night .tag,
html[data-theme="dark"] .tag { background: #1c2822; color: #d7e2db; }
.kp-night .tag-brand,
html[data-theme="dark"] .tag-brand { background: #1d3528; color: #9ce6ba; }
.kp-night .tag-info,
html[data-theme="dark"] .tag-info { background: #163044; color: #93c5fd; }

/* ---- Dialog ---- */
.dialog {
  box-sizing: border-box; width: min(92vw, 440px); max-height: 90vh; overflow: auto;
  padding: 20px; border: 0; border-radius: var(--ui-r-card);
  background: var(--ui-surface); color: var(--ui-ink); box-shadow: var(--ui-shadow-dialog);
}
.dialog::backdrop { background: var(--ui-backdrop); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (prefers-reduced-motion: reduce) {
  .input, .btn { transition: none !important; }
}
