/* Dent Group panel — RTL Persian admin UI.
   No build step, no framework, no webfont fetch (the CSP is self-only and the
   box serves Iran-adjacent traffic; system fonts render Persian correctly and
   cost nothing). */

:root {
  --bg:        #f4f6f8;
  --surface:   #ffffff;
  --ink:       #1b2430;
  --ink-soft:  #5c6875;
  --line:      #e2e7ec;
  --brand:     #1f6feb;
  --brand-ink: #ffffff;
  --ok:        #167c4a;
  --ok-bg:     #e7f6ee;
  --warn:      #92610a;
  --warn-bg:   #fdf3dd;
  --err:       #b3261e;
  --err-bg:    #fdecea;
  --info:      #10557f;
  --info-bg:   #e6f1f8;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.75 system-ui, 'Vazirmatn', 'IRANSans', 'Segoe UI', Tahoma, sans-serif;
  font-feature-settings: 'ss01';
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip { position: absolute; inset-inline-start: -9999px; }
.skip:focus { inset-inline-start: 1rem; top: .5rem; background: #fff; padding: .5rem 1rem; z-index: 10; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 1.25rem; height: 56px;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.spacer { flex: 1; }
.whoami { display: flex; flex-direction: column; line-height: 1.35; text-align: start; font-size: .85rem; }
.whoami .role { color: var(--ink-soft); font-size: .78rem; }
.inline { display: inline; margin: 0; }

/* ----------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 232px 1fr; align-items: start; }
.sidenav {
  background: var(--surface); border-inline-start: 1px solid var(--line);
  min-height: calc(100vh - 56px); padding: 1rem .75rem;
  position: sticky; top: 56px;
}
.navgroup { margin-bottom: 1.25rem; }
.navgroup-label {
  font-size: .74rem; letter-spacing: .02em; color: var(--ink-soft);
  padding: 0 .6rem .4rem; font-weight: 600;
}
.navlink {
  display: block; padding: .45rem .6rem; border-radius: 8px;
  color: var(--ink); font-size: .9rem;
}
.navlink:hover { background: var(--bg); text-decoration: none; }
.navlink.is-active { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

.content { padding: 1.5rem 1.75rem 4rem; min-width: 0; }

.page-head { margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: .75rem; }
.page-head h1 { margin: 0; font-size: 1.35rem; }
.page-head .lead { margin: 0; color: var(--ink-soft); font-size: .9rem; flex-basis: 100%; }
.page-actions { margin-inline-start: auto; display: flex; gap: .5rem; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .42rem .9rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: .88rem; cursor: pointer; background: var(--surface);
  color: var(--ink); border-color: var(--line); white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--bg); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: #1a5fd0; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { color: var(--err); border-color: #f0c4c1; }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: .22rem .55rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------------------------------------------------------------- alerts */
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert.is-ok   { background: var(--ok-bg);   color: var(--ok); }
.alert.is-err  { background: var(--err-bg);  color: var(--err); }
.alert.is-warn { background: var(--warn-bg); color: var(--warn); }
.alert.is-info { background: var(--info-bg); color: var(--info); }

/* --------------------------------------------------------------- filters */
.dg-filters {
  display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem;
}
.dg-filter { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; color: var(--ink-soft); }
.dg-filter input, .dg-filter select {
  font: inherit; font-size: .88rem; color: var(--ink);
  padding: .35rem .55rem; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; min-width: 9rem;
}
.dg-filter input:focus, .dg-filter select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.dg-range { display: flex; gap: .35rem; }
.dg-range input { min-width: 7rem; }
.dg-filter-actions { display: flex; gap: .5rem; margin-inline-start: auto; }

/* ---------------------------------------------------------------- tables */
.dg-table-wrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow);
}
.dg-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.dg-table th, .dg-table td {
  padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-align: start;
  vertical-align: middle;
}
.dg-table thead th {
  background: #fafbfc; font-weight: 600; font-size: .82rem; color: var(--ink-soft);
  position: sticky; top: 56px; z-index: 1; white-space: nowrap;
}
.dg-table tbody tr:hover { background: #fbfcfd; }
.dg-table tbody tr:last-child td { border-bottom: 0; }
.dg-table tfoot td {
  background: #fafbfc; font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0;
}
.dg-sort { color: inherit; }
.dg-sort:hover { color: var(--brand); }
.align-center { text-align: center; }
.align-end    { text-align: end; }
.align-num    { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dg-empty { text-align: center; color: var(--ink-soft); padding: 2.5rem 1rem; }
.dg-actions { white-space: nowrap; }
.dg-actions .btn + .btn { margin-inline-start: .3rem; }
.dg-muted { color: var(--ink-soft); }
.dg-date { white-space: nowrap; }
.dg-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dg-money.is-neg { color: var(--err); }

/* Rows a screen wants to call out (e.g. a rejected order). */
.row-warn { background: var(--warn-bg) !important; }
.row-err  { background: var(--err-bg)  !important; }

.dg-badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.dg-badge.is-ok    { background: var(--ok-bg);   color: var(--ok); }
.dg-badge.is-warn  { background: var(--warn-bg); color: var(--warn); }
.dg-badge.is-err   { background: var(--err-bg);  color: var(--err); }
.dg-badge.is-info  { background: var(--info-bg); color: var(--info); }
.dg-badge.is-muted { background: #eef1f4;        color: var(--ink-soft); }

/* -------------------------------------------------------- table footer */
.dg-tablefoot {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem;
  margin-top: .85rem; font-size: .85rem; color: var(--ink-soft);
}
.dg-pager, .dg-per { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.dg-per span { margin-inline-end: .25rem; }
.dg-page {
  display: inline-block; min-width: 2rem; text-align: center;
  padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--ink);
}
.dg-page:hover { background: var(--bg); text-decoration: none; }
.dg-page.is-active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.dg-page.is-disabled, .dg-page.is-gap { opacity: .45; pointer-events: none; }
.dg-filtered { color: var(--warn); }

/* ----------------------------------------------------------------- cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.15rem; box-shadow: var(--shadow);
}
.card .k { font-size: .82rem; color: var(--ink-soft); }
.card .v { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.card .sub { font-size: .78rem; color: var(--ink-soft); margin-top: .15rem; }
.card.is-err .v  { color: var(--err); }
.card.is-warn .v { color: var(--warn); }
.card.is-ok .v   { color: var(--ok); }

/* ----------------------------------------------------------------- forms */
.form-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; box-shadow: var(--shadow); max-width: 46rem;
}
.form-card label { display: block; margin-bottom: 1rem; font-size: .86rem; color: var(--ink-soft); }
.form-card input[type=text], .form-card input[type=password], .form-card input[type=email],
.form-card input[type=number], .form-card select, .form-card textarea {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-size: .92rem; color: var(--ink);
  padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.form-card .hint { font-size: .78rem; color: var(--ink-soft); margin-top: .25rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.25rem; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.perm-group { border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.perm-group h3 { margin: 0 0 .5rem; font-size: .92rem; }
.perm-group label { display: flex; gap: .45rem; align-items: start; margin-bottom: .4rem; font-size: .86rem; color: var(--ink); }
.perm-group input[type=checkbox] { margin-top: .35rem; }

/* ----------------------------------------------------------------- login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 2rem 2.25rem; width: min(24rem, 92vw); box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 1.25rem; font-size: 1.15rem; text-align: center; }
.login-card label { display: block; margin-bottom: 1rem; font-size: .85rem; color: var(--ink-soft); }
.login-card input {
  display: block; width: 100%; margin-top: .3rem; font: inherit; font-size: .95rem;
  padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px;
}

/* --------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidenav {
    position: static; min-height: 0; border-inline-start: 0; border-bottom: 1px solid var(--line);
    display: flex; gap: 1rem; overflow-x: auto; padding: .6rem .75rem;
  }
  .navgroup { margin: 0; display: flex; gap: .3rem; align-items: center; white-space: nowrap; }
  .navgroup-label { padding: 0; }
  .content { padding: 1rem; }
  .dg-table thead th { position: static; }
}

/* A row action that writes is a one-button form, not a link: the Router only
   enforces CSRF on non-GET, so a write behind an <a href> has none. The form
   has to sit inline so a row of actions still reads as a row of buttons. */
.dg-rowform { display: inline; margin: 0; }
.dg-actions .dg-rowform + .dg-rowform > .btn,
.dg-actions .dg-rowform + .btn,
.dg-actions .btn + .dg-rowform > .btn { margin-inline-start: .3rem; }
