/* =========================================================================
   Dress CMS — shadcn/ui-inspired design system (hand-written, no build step)
   Mirrors shadcn's design tokens (neutral palette, radius, focus rings) so the
   UI feels like shadcn without requiring Node/Tailwind on the cPanel server.
   Mobile-first.
   ========================================================================= */

:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --ring: 240 5% 64.9%;
  --radius: 0.6rem;

  --green: 142 71% 45%;
  --amber: 38 92% 50%;
  --red: 0 72% 51%;
  --blue: 221 83% 53%;
  --violet: 262 83% 58%;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: hsl(240 4.8% 97%);
  color: hsl(var(--foreground));
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ── Layout shell ───────────────────────────────────────────────────────── */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem;
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
}
.topbar__brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 600; }
.topbar__brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.topbar__spacer { flex: 1; }

.nav-links { display: none; align-items: center; gap: 0.25rem; }
.nav-links a {
  padding: 0.4rem 0.7rem; border-radius: var(--radius);
  color: hsl(var(--muted-foreground)); font-weight: 500;
}
.nav-links a:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.nav-links a.active { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

.nav-toggle {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  border: 1px solid hsl(var(--border)); background: hsl(var(--background));
  cursor: pointer;
}
.mobile-nav {
  display: none; flex-direction: column; gap: 0.15rem;
  padding: 0.5rem 1rem 0.75rem;
  background: hsl(var(--background)); border-bottom: 1px solid hsl(var(--border));
}
.mobile-nav.open { display: flex; }
.mobile-nav a { padding: 0.6rem 0.7rem; border-radius: var(--radius); color: hsl(var(--muted-foreground)); font-weight: 500; }
.mobile-nav a.active, .mobile-nav a:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

.container { width: 100%; max-width: 1400px; margin: 0 auto; padding: 1rem; flex: 1; }

.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head__title { font-size: 1.4rem; }
.page-head__sub { color: hsl(var(--muted-foreground)); font-size: 0.9rem; margin-top: 0.15rem; }
.page-head__actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card__head { padding: 1rem 1.1rem 0.6rem; }
.card__title { font-size: 1rem; }
.card__desc { color: hsl(var(--muted-foreground)); font-size: 0.85rem; margin-top: 0.15rem; }
.card__body { padding: 0.6rem 1.1rem 1.1rem; }
.card__body--flush { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.stat { display: flex; flex-direction: column; gap: 0.2rem; }
.stat__num { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; }
.stat__label { color: hsl(var(--muted-foreground)); font-size: 0.85rem; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  height: 38px; padding: 0 0.9rem; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  transition: opacity .15s, background .15s; white-space: nowrap;
}
.btn:hover { opacity: 0.9; }
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.btn--outline { background: hsl(var(--background)); color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.btn--outline:hover { background: hsl(var(--muted)); opacity: 1; }
.btn--ghost { background: transparent; color: hsl(var(--foreground)); }
.btn--ghost:hover { background: hsl(var(--muted)); }
.btn--danger { background: hsl(var(--red)); }
.btn--sm { height: 32px; padding: 0 0.65rem; font-size: 0.82rem; }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; line-height: 1;
  border: 1px solid hsl(var(--border)); background: hsl(var(--muted)); color: hsl(var(--foreground));
}
.badge--dot::before { content: ""; width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.badge--new      { color: hsl(var(--blue));   background: hsl(var(--blue) / 0.12);   border-color: hsl(var(--blue) / 0.25); }
.badge--awaiting { color: hsl(var(--amber));  background: hsl(var(--amber) / 0.14);  border-color: hsl(var(--amber) / 0.3); }
.badge--progress { color: hsl(var(--violet)); background: hsl(var(--violet) / 0.12); border-color: hsl(var(--violet) / 0.25); }
.badge--ready    { color: hsl(var(--green));  background: hsl(var(--green) / 0.13);  border-color: hsl(var(--green) / 0.3); }
.badge--done     { color: hsl(var(--muted-foreground)); }
.badge--cancel   { color: hsl(var(--red)); background: hsl(var(--red) / 0.1); border-color: hsl(var(--red) / 0.25); }
.badge--unpaid   { color: hsl(var(--red));   background: hsl(var(--red) / 0.1);   border-color: hsl(var(--red) / 0.25); }
.badge--partial  { color: hsl(var(--amber)); background: hsl(var(--amber) / 0.14); border-color: hsl(var(--amber) / 0.3); }
.badge--paid     { color: hsl(var(--green)); background: hsl(var(--green) / 0.13); border-color: hsl(var(--green) / 0.3); }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; }
.field label { font-size: 0.85rem; font-weight: 500; }
.field .hint { font-size: 0.78rem; color: hsl(var(--muted-foreground)); }
.input, .select, .textarea {
  width: 100%; padding: 0.5rem 0.7rem; font-size: 0.92rem; color: hsl(var(--foreground));
  background: hsl(var(--background)); border: 1px solid hsl(var(--input)); border-radius: var(--radius);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid hsl(var(--ring)); outline-offset: 1px; border-color: hsl(var(--ring));
}
.textarea { min-height: 110px; resize: vertical; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }
/* Quote line-item rows must not wrap */
.li-row { flex-wrap: nowrap !important; align-items: center !important; }
.li-row > * { min-width: 0 !important; }
.li-row .btn { flex-shrink: 0; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.65rem 0.8rem; border-bottom: 1px solid hsl(var(--border)); }
.table th { color: hsl(var(--muted-foreground)); font-weight: 500; font-size: 0.8rem; }
.table tbody tr:hover { background: hsl(var(--muted) / 0.6); }
.table tbody tr.row-link { cursor: pointer; }
.table tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

/* ── Alerts / flash ─────────────────────────────────────────────────────── */
.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); border: 1px solid hsl(var(--border)); margin-bottom: 0.8rem; font-size: 0.9rem; }
.alert--success { background: hsl(var(--green) / 0.1); border-color: hsl(var(--green) / 0.3); color: hsl(142 71% 30%); }
.alert--error   { background: hsl(var(--red) / 0.08); border-color: hsl(var(--red) / 0.3); color: hsl(0 72% 42%); }
.alert--info    { background: hsl(var(--blue) / 0.08); border-color: hsl(var(--blue) / 0.3); color: hsl(221 83% 40%); }

/* ── Dialog (native <dialog>) ───────────────────────────────────────────── */
dialog {
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  padding: 0; max-width: 540px; width: calc(100% - 2rem);
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
dialog::backdrop { background: rgba(0,0,0,0.4); }
.dialog__head { padding: 1rem 1.1rem 0; }
.dialog__body { padding: 0.8rem 1.1rem 1.1rem; }
.dialog__foot { padding: 0 1.1rem 1.1rem; display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Email thread (chat) ─────────────────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: 1rem; padding: 0.25rem 0.25rem 0.75rem 0; max-height: 480px; overflow-y: auto; scroll-behavior: smooth; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg--outbound { align-self: flex-end; align-items: flex-end; }
.msg--inbound  { align-self: flex-start; align-items: flex-start; }
.msg__bubble { padding: 0.65rem 1rem; border-radius: 1.1rem; font-size: 0.91rem; white-space: pre-line; word-break: break-word; line-height: 1.55; }
.msg--outbound .msg__bubble { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-bottom-right-radius: 0.3rem; }
.msg--inbound  .msg__bubble { background: hsl(var(--muted)); color: hsl(var(--foreground)); border-bottom-left-radius: 0.3rem; }
.msg__subject { font-size: 0.74rem; opacity: 0.65; margin-bottom: 0.25rem; font-style: italic; }
.msg__footer  { display: flex; align-items: center; gap: 0.4rem; font-size: 0.74rem; color: hsl(var(--muted-foreground)); margin-top: 0.3rem; flex-wrap: wrap; }
.msg--outbound .msg__footer { justify-content: flex-end; }
.msg__body { padding: 0.8rem; white-space: pre-wrap; word-break: break-word; font-size: 0.92rem; }
.compose-area { padding: 1rem 0 0; }
.compose-area__title { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.5rem; }
.compose-toggles { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.45rem; }
.compose-toggle { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.81rem; cursor: pointer; padding: 0.22rem 0.6rem; border: 1px solid hsl(var(--border)); border-radius: 999px; background: hsl(var(--background)); user-select: none; white-space: nowrap; transition: background .12s; }
.compose-toggle:hover { background: hsl(var(--muted)); }
.compose-toggle input[type=checkbox] { cursor: pointer; accent-color: hsl(var(--primary)); }

/* ── Customer banner ────────────────────────────────────────────────────── */
.customer-banner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 0.85rem 1.2rem; margin-bottom: 0.75rem; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.customer-banner__avatar { width: 42px; height: 42px; border-radius: 999px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); display: flex; align-items: center; justify-content: center; font-size: 1.05rem; font-weight: 700; flex-shrink: 0; }
.customer-banner__name { font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.customer-banner__contacts { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: 0.25rem; }
.customer-banner__contact { font-size: 0.88rem; color: hsl(var(--muted-foreground)); text-decoration: none; }
.customer-banner__contact:hover { color: hsl(var(--foreground)); text-decoration: underline; }
.customer-banner__right { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

/* ── Image gallery ──────────────────────────────────────────────────────── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 1px solid hsl(var(--border)); }
.gallery figure { margin: 0; }
.gallery figcaption { font-size: 0.72rem; color: hsl(var(--muted-foreground)); margin-top: 0.2rem; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.muted { color: hsl(var(--muted-foreground)); }
.small { font-size: 0.82rem; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.flex { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.divider { height: 1px; background: hsl(var(--border)); margin: 0.8rem 0; }
.empty { text-align: center; color: hsl(var(--muted-foreground)); padding: 2rem 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.9rem; font-size: 0.9rem; }
.kv dt { color: hsl(var(--muted-foreground)); }
.kv dd { margin: 0; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }

/* ── Responsive (tablet+) ───────────────────────────────────────────────── */
@media (min-width: 720px) {
  .nav-links { display: flex; }
  .nav-toggle { display: none; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .container { padding: 1.5rem; }
}
@media (min-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .detail-cols { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 1.2rem; align-items: start; }
}
