/* PersianWay ERP — Business OS shell
   RTL، دسکتاپ‌محور و کاملاً واکنش‌گرا. بدون هیچ دارایی بیرونی. */

:root {
  --bg:        #f6f6f4;
  --bg-elev:   #ffffff;
  --bg-sunken: #eeeeeb;
  --fg:        #16211f;
  --fg-muted:  #66716e;
  --fg-faint:  #939c99;
  --line:      #e2e4e1;
  --line-soft: #ecedea;
  --accent:    #0f6f5c;
  --accent-fg: #ffffff;
  --accent-sunken: #e6f1ee;

  --ok:      #157f4a;
  --info:    #1f6aa8;
  --warn:    #9a6413;
  --danger:  #a63421;
  --neutral: #6b7674;

  --radius:   12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,26,24,.05), 0 6px 18px -10px rgba(16,26,24,.18);
  --sidebar-w: 17rem;
  --font: "Vazirmatn", "IRANSans", system-ui, "Segoe UI", Tahoma, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #101413;
    --bg-elev:   #171d1b;
    --bg-sunken: #0b0f0e;
    --fg:        #e9edeb;
    --fg-muted:  #98a3a0;
    --fg-faint:  #6d7a77;
    --line:      #262e2c;
    --line-soft: #1f2725;
    --accent:    #46b295;
    --accent-fg: #08120f;
    --accent-sunken: #12241f;

    --ok:      #4cb87c;
    --info:    #5aa4dd;
    --warn:    #d1a054;
    --danger:  #e0776a;
    --neutral: #8b9997;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 22px -12px rgba(0,0,0,.7);
  }
}

/* انتخاب صریح کاربر بر ترجیح سیستم می‌چربد. */
:root[data-theme="dark"] {
  --bg:        #101413;
  --bg-elev:   #171d1b;
  --bg-sunken: #0b0f0e;
  --fg:        #e9edeb;
  --fg-muted:  #98a3a0;
  --fg-faint:  #6d7a77;
  --line:      #262e2c;
  --line-soft: #1f2725;
  --accent:    #46b295;
  --accent-fg: #08120f;
  --accent-sunken: #12241f;

  --ok:      #4cb87c;
  --info:    #5aa4dd;
  --warn:    #d1a054;
  --danger:  #e0776a;
  --neutral: #8b9997;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 22px -12px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.ico { flex: none; }

/* ───────────────────────── shell ───────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: 1.15rem .85rem 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .35rem .5rem 1.1rem;
}
.brand-mark {
  width: 2.2rem; height: 2.2rem;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 700; font-size: .95rem;
  letter-spacing: -.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: .95rem; }
.brand-text span { font-size: .72rem; color: var(--fg-faint); }

.nav-label {
  font-size: .7rem;
  color: var(--fg-faint);
  padding: 1rem .6rem .35rem;
  letter-spacing: .04em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: .875rem;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg-sunken); color: var(--fg); }
.nav-item.is-active { background: var(--accent-sunken); color: var(--accent); font-weight: 600; }
.nav-item .count {
  margin-inline-start: auto;
  font-size: .72rem;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot { margin-top: auto; padding-top: 1rem; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* ───────────────────────── topbar ───────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: .85rem 1.5rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}

.search {
  flex: 1 1 18rem;
  min-width: 0;
  position: relative;
  display: flex; align-items: center;
}
.search .ico {
  position: absolute; inset-inline-start: .75rem;
  color: var(--fg-faint); pointer-events: none;
}
.search input {
  width: 100%;
  padding: .55rem 2.4rem .55rem 2.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit; font-size: .875rem;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-sunken);
}
.search kbd {
  position: absolute; inset-inline-end: .6rem;
  font-family: var(--mono); font-size: .68rem;
  color: var(--fg-faint);
  border: 1px solid var(--line); border-radius: 5px;
  padding: 0 .3rem;
}

.topbar-actions { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }

.icon-btn {
  width: 2.2rem; height: 2.2rem;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg-muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--fg); border-color: var(--fg-faint); }

.userchip {
  display: flex; align-items: center; gap: .55rem;
  padding: .3rem .7rem .3rem .35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
}
.avatar {
  width: 1.75rem; height: 1.75rem; border-radius: 50%;
  background: var(--accent-sunken); color: var(--accent);
  display: grid; place-items: center;
  font-size: .78rem; font-weight: 700;
}
.userchip .who { display: flex; flex-direction: column; line-height: 1.2; }
.userchip .who b { font-size: .8rem; font-weight: 600; }
.userchip .who span { font-size: .68rem; color: var(--fg-faint); }

/* ───────────────────────── content ───────────────────────── */

.content { padding: 1.5rem 1.5rem 4rem; flex: 1; }

.page-head { margin-bottom: 1.5rem; }
.page-head h1 { margin: 0 0 .25rem; font-size: 1.4rem; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--fg-muted); font-size: .875rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: .75rem;
  margin: 1.25rem 0 1.75rem;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .8rem .95rem;
}
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { font-size: .75rem; color: var(--fg-muted); }

.filters { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.chip {
  font-size: .78rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg-muted);
  cursor: pointer;
}
.chip:hover { color: var(--fg); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* section */

.section { margin-bottom: 2.25rem; scroll-margin-top: 5rem; }
.section-head {
  display: flex; align-items: center; gap: .7rem;
  padding-bottom: .7rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.section-head .tile {
  width: 2rem; height: 2rem; border-radius: 8px;
  background: var(--bg-sunken); color: var(--fg-muted);
  display: grid; place-items: center;
}
.section-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.section-head .en { font-size: .72rem; color: var(--fg-faint); letter-spacing: .02em; }
.section-head .n {
  margin-inline-start: auto; font-size: .72rem; color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: .85rem;
}

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  transition: border-color .14s, box-shadow .14s, transform .14s;
}
.card:hover { border-color: var(--fg-faint); box-shadow: var(--shadow); }
.card.is-locked { background: var(--bg-sunken); }
.card.is-locked .card-title b { color: var(--fg-muted); }

.card-top { display: flex; align-items: flex-start; gap: .7rem; margin-bottom: .6rem; }
.card-tile {
  width: 2.4rem; height: 2.4rem; border-radius: 10px;
  background: var(--accent-sunken); color: var(--accent);
  display: grid; place-items: center; flex: none;
}
.card.is-locked .card-tile { background: var(--bg-elev); color: var(--fg-faint); }
.card-title { min-width: 0; }
.card-title b { display: block; font-size: .95rem; font-weight: 650; letter-spacing: -.01em; }
.card-title .en { font-size: .72rem; color: var(--fg-faint); }

.card-desc {
  margin: 0 0 .85rem;
  font-size: .82rem; color: var(--fg-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
}

.card-meta {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  font-size: .74rem; color: var(--fg-faint);
  margin-bottom: .85rem;
}
.card-meta .host { font-family: var(--mono); font-size: .72rem; direction: ltr; }

.status {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .72rem;
}
.status .dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.status-active      { color: var(--ok); }
.status-development { color: var(--info); }
.status-testing     { color: var(--warn); }
.status-planning    { color: var(--neutral); }
.status-maintenance { color: var(--warn); }
.status-archived    { color: var(--fg-faint); }

.card-foot { margin-top: auto; display: flex; gap: .45rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .8rem; font-weight: 550;
  padding: .45rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-sunken); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { background: var(--bg-sunken); color: var(--fg); }
.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: .3rem .6rem; font-size: .75rem; }
.grow { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .7rem; padding: .12rem .5rem;
  border-radius: 999px; border: 1px solid var(--line);
  color: var(--fg-muted);
}
.pill-lock { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }

.empty {
  text-align: center; padding: 4rem 1rem; color: var(--fg-muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ───────────────────────── detail ───────────────────────── */

.detail-head {
  display: flex; align-items: flex-start; gap: 1rem;
  padding-bottom: 1.25rem; margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}
.detail-head .card-tile { width: 3.2rem; height: 3.2rem; border-radius: 12px; }
.detail-head h1 { margin: 0; font-size: 1.35rem; }
.detail-head .en { color: var(--fg-faint); font-size: .8rem; }
.detail-actions { margin-inline-start: auto; display: flex; gap: .5rem; }

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 .8rem; font-size: .85rem; color: var(--fg-muted); font-weight: 600; }
.panel p { margin: 0; font-size: .9rem; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .9rem 1.5rem; }
.kv > div { min-width: 0; }
.kv dt { font-size: .72rem; color: var(--fg-faint); margin-bottom: .15rem; }
.kv dd { margin: 0; font-size: .85rem; word-break: break-word; }
.kv dd.mono { font-family: var(--mono); direction: ltr; text-align: right; font-size: .8rem; }
.kv dd a { color: var(--accent); }

/* ───────────────────────── forms / tables ───────────────────────── */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .76rem; color: var(--fg-muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: .85rem;
  padding: .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}
.field textarea { min-height: 5rem; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-sunken);
}
.field .hint { font-size: .7rem; color: var(--fg-faint); }
.check { flex-direction: row; align-items: center; gap: .5rem; }
.check input { width: auto; }

.form-actions { display: flex; gap: .6rem; margin-top: 1.25rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: .6rem .8rem; text-align: right; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { font-size: .74rem; color: var(--fg-muted); font-weight: 600; background: var(--bg-sunken); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-sunken); }
td.mono { font-family: var(--mono); direction: ltr; text-align: right; font-size: .78rem; }
td select { font: inherit; font-size: .76rem; padding: .2rem .35rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }

.tabs { display: flex; gap: .3rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.tab {
  padding: .5rem .9rem; font-size: .84rem; color: var(--fg-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--fg); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.note {
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  color: var(--fg);
  border-radius: var(--radius-sm);
  padding: .7rem .9rem; font-size: .82rem; margin-bottom: 1rem;
}

/* ───────────────────────── login ───────────────────────── */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.login-card {
  width: 100%; max-width: 23rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; padding-bottom: 1.5rem; }
.login-card h1 { margin: 0 0 .3rem; font-size: 1.1rem; text-align: center; }
.login-card > p { margin: 0 0 1.5rem; text-align: center; color: var(--fg-muted); font-size: .82rem; }
.login-card .field { margin-bottom: .9rem; }
.error {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem; font-size: .8rem; margin-bottom: 1rem;
}

.error-page { display: grid; place-items: center; min-height: 60vh; text-align: center; }
.error-page b { font-size: 3rem; display: block; color: var(--fg-faint); }

/* ───────────────────────── responsive ───────────────────────── */

.sidebar-toggle { display: none; }

@media (max-width: 60rem) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-end: 0;
    width: min(var(--sidebar-w), 84vw);
    transform: translateX(100%);
    transition: transform .2s ease;
    z-index: 40;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30;
  }
  .sidebar-toggle { display: grid; }
  .content { padding: 1.25rem 1rem 3rem; }
  .topbar { padding: .7rem 1rem; }
  .userchip .who { display: none; }
}

@media (max-width: 32rem) {
  .cards { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .search kbd { display: none; }
}

@media print { .sidebar, .topbar { display: none; } }
