:root {
  --ink: #17202a;
  --muted: #77808f;
  --line: #e6e9ee;
  --panel: #ffffff;
  --canvas: #f6f7f9;
  --nav: #11151c;
  --accent: #2f6fed;
  --accent-soft: #edf4ff;
  --green: #138a53;
  --green-soft: #eaf9f1;
  --amber: #b96d0b;
  --amber-soft: #fff6e8;
  --red: #c53c46;
  --red-soft: #fff0f1;
  --violet: #7453c5;
  --violet-soft: #f4efff;
  --shadow: 0 8px 30px rgba(19, 30, 52, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: Vazirmatn, IRANSansX, Tahoma, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.7;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 0 0 auto;
  width: 258px;
  padding: 24px 18px;
  color: #d9dee8;
  background: linear-gradient(180deg, #141922 0%, #0d1117 100%);
  z-index: 40;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; margin: 2px 6px 30px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px;
  color: #17202a; background: linear-gradient(145deg, #f8d76e, #d9a820); font-size: 23px; font-weight: 900;
}
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand small { color: #8e99ab; }
.nav-section { margin: 22px 10px 8px; color: #697588; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.nav-link {
  display: flex; align-items: center; gap: 11px; min-height: 44px; margin: 4px 0; padding: 9px 12px;
  border-radius: 11px; color: #adb6c5; transition: .18s ease;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-link.active { color: #fff; background: rgba(47,111,237,.22); box-shadow: inset -3px 0 #6395ff; }
.nav-icon { width: 22px; text-align: center; font-size: 17px; opacity: .95; }
.sidebar-footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.user-mini { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #293241; color: #fff; font-weight: 800; }
.user-mini strong { display: block; color: #fff; font-size: 13px; }
.user-mini small { color: #7e899a; }
.logout-button { width: 100%; margin-top: 8px; padding: 9px; border: 0; border-radius: 9px; color: #aeb7c5; background: transparent; cursor: pointer; text-align: right; }
.logout-button:hover { background: rgba(255,255,255,.05); color: #fff; }

.main { min-height: 100vh; margin-right: 258px; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  min-height: 74px; padding: 14px 32px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.topbar-title strong { display: block; font-size: 17px; }
.topbar-title span { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 22px; }
.content { max-width: 1480px; margin: 0 auto; padding: 30px 32px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 25px; line-height: 1.4; }
.page-head p { margin: 0; color: var(--muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 9px 17px;
  border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: #fff; cursor: pointer;
  font-weight: 700; transition: .16s ease;
}
.button:hover { transform: translateY(-1px); border-color: #cdd3dc; box-shadow: 0 6px 16px rgba(20,30,50,.08); }
.button.primary { color: #fff; border-color: #151a22; background: #151a22; }
.button.accent { color: #fff; border-color: var(--accent); background: var(--accent); }
.button.danger { color: var(--red); background: var(--red-soft); border-color: #f4cfd2; }
.button.small { min-height: 35px; padding: 6px 12px; border-radius: 9px; font-size: 12px; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 20px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.stat-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-size: 18px; }
.stat-value { margin-top: 14px; font-size: 28px; font-weight: 900; line-height: 1.2; }
.stat-note { margin-top: 5px; color: var(--muted); font-size: 12px; }
.dashboard-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.market-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; }
.market-card { padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: linear-gradient(160deg,#fff,#fafbfc); }
.market-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.market-name { display: flex; align-items: center; gap: 9px; font-weight: 800; }
.metal-dot { width: 11px; height: 11px; border-radius: 50%; background: #d9aa29; box-shadow: 0 0 0 5px #fff7db; }
.metal-dot.silver { background: #8e99a8; box-shadow: 0 0 0 5px #eef1f5; }
.market-price { margin: 18px 0 2px; font-size: 24px; font-weight: 900; direction: ltr; text-align: right; }
.market-price small { margin-right: 5px; color: var(--muted); font-size: 11px; font-weight: 500; }
.market-meta { color: var(--muted); font-size: 12px; }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; background: #eef1f5; color: #596273; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.ok, .status.healthy, .status.completed, .status.committed { color: var(--green); background: var(--green-soft); }
.status.error, .status.failed, .status.calculation_error, .status.market_unavailable, .status.expired { color: var(--red); background: var(--red-soft); }
.status.degraded, .status.queued, .status.previewed { color: var(--amber); background: var(--amber-soft); }
.status.running, .status.recalculating { color: var(--accent); background: var(--accent-soft); }

.message-list { display: grid; gap: 8px; margin-bottom: 18px; }
.message { padding: 12px 15px; border: 1px solid #cfe0ff; border-radius: 11px; background: var(--accent-soft); color: #2555a7; }
.message.success { border-color: #c9ecd9; background: var(--green-soft); color: #0f7545; }
.message.error { border-color: #f2c7cb; background: var(--red-soft); color: #a72b35; }
.message.warning { border-color: #f4dfb8; background: var(--amber-soft); color: #925305; }

.filters { display: grid; grid-template-columns: minmax(240px, 1fr) 180px 190px auto; gap: 10px; padding: 15px; margin-bottom: 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.ui-input {
  width: 100%; min-height: 43px; padding: 9px 12px; border: 1px solid #dfe3e9; border-radius: 10px;
  color: var(--ink); background: #fff; outline: none; transition: .15s ease;
}
.ui-input:focus { border-color: #8bb0fb; box-shadow: 0 0 0 3px rgba(47,111,237,.11); }
select.ui-input { cursor: pointer; }
textarea.ui-input { resize: vertical; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
.field label { display: block; margin: 0 2px 6px; font-size: 12px; font-weight: 800; }
.field .helptext, .helptext { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.errorlist { margin: 5px 0 0; padding: 0; list-style: none; color: var(--red); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-section { margin-top: 18px; padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form-section h2 { margin: 0 0 16px; font-size: 16px; }
.form-actions { position: sticky; bottom: 14px; display: flex; justify-content: flex-start; gap: 10px; margin-top: 20px; padding: 12px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 13px; backdrop-filter: blur(12px); }

.bulk-bar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 14px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.check-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.product-list { display: grid; gap: 12px; }
.product-card { overflow: hidden; background: #fff; border: 1px solid #dfe3e8; border-radius: 14px; box-shadow: 0 5px 18px rgba(22,31,48,.04); }
.product-summary { display: grid; grid-template-columns: 34px minmax(220px,1fr) 145px 145px 118px 34px; align-items: center; gap: 12px; min-height: 76px; padding: 12px 16px; cursor: pointer; list-style: none; }
.product-summary::-webkit-details-marker { display: none; }
.product-summary:hover { background: #fcfcfd; }
.product-identity strong { display: block; font-size: 14px; }
.product-identity small { color: var(--muted); direction: ltr; }
.product-updated { color: var(--muted); font-size: 11px; }
.product-updated strong { display: block; color: #4f5867; font-size: 11px; }
.product-price { text-align: left; direction: ltr; color: var(--green); font-size: 16px; font-weight: 900; }
.product-price small { font-size: 9px; }
.chevron { color: #8e97a5; font-size: 18px; transition: transform .18s ease; }
details[open] .chevron { transform: rotate(180deg); }
.product-detail { padding: 0 16px 16px; border-top: 1px solid var(--line); background: #fbfcfd; }
.product-info-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; }
.product-error { margin: 0 0 12px; padding: 10px 12px; color: var(--red); background: var(--red-soft); border-radius: 9px; }
.quick-grid { display: grid; grid-template-columns: repeat(6, minmax(120px,1fr)); gap: 9px; }
.quick-field { padding: 10px; border: 1px solid #dfe5ed; border-radius: 10px; background: #fff; }
.quick-field label { display: block; margin-bottom: 5px; font-size: 11px; font-weight: 800; }
.quick-field.weight { border-color: #c8ddf6; background: #f2f8ff; color: #195a92; }
.quick-field.labor { border-color: #e4d3f1; background: #faf5ff; color: #77418f; }
.quick-field.profit { border-color: #c8ead7; background: #f0fbf5; color: #167046; }
.quick-field.tax { border-color: #f0d6ad; background: #fff8ed; color: #9a5d0d; }
.quick-field.discount { border-color: #f1cbd0; background: #fff5f6; color: #a82e3b; }
.quick-field .ui-input { min-height: 36px; padding: 6px 8px; background: rgba(255,255,255,.8); }
.quick-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
.data-table th { color: #5f6877; background: #fafbfc; font-size: 11px; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fcfcfd; }
.ltr { direction: ltr; text-align: left; }
.muted { color: var(--muted); }

.formula-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.formula-card { padding: 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.formula-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.formula-card h2 { margin: 0; font-size: 17px; }
.formula-card p { margin: 4px 0 0; color: var(--muted); }
.steps { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.step { display: grid; grid-template-columns: 38px minmax(220px,.8fr) 1.2fr; align-items: center; gap: 12px; min-height: 72px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 900; }
.step strong { font-size: 14px; }
.step-expression { color: var(--muted); direction: rtl; }
.default-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.default-box { padding: 12px; border-radius: 11px; background: #f8f9fb; border: 1px solid var(--line); }
.default-box span { display: block; color: var(--muted); font-size: 11px; }
.default-box strong { display: block; margin-top: 4px; font-size: 16px; }
.steps.compact .step { min-height: 60px; grid-template-columns: 34px minmax(160px,.8fr) 1.2fr; }
.source-details { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 16px 0; }
.source-details > div { padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; }
.source-details span { display: block; color: var(--muted); font-size: 10px; }
.source-details strong { display: block; margin-top: 3px; font-size: 12px; }
.history-filters { grid-template-columns: minmax(240px,1fr) 190px auto; }
.audit-filters { grid-template-columns: minmax(260px,1fr) auto; }
.job-summary { display: grid; grid-template-columns: 54px minmax(220px,1fr) 120px 280px 30px; align-items: center; gap: 12px; min-height: 76px; padding: 12px 16px; cursor: pointer; list-style: none; }
.job-summary::-webkit-details-marker { display: none; }
.job-id { display: grid; place-items: center; width: 43px; height: 43px; border-radius: 12px; color: var(--accent); background: var(--accent-soft); font-weight: 900; direction: ltr; }
.job-summary small { display: block; color: var(--muted); }
.job-numbers { display: flex; justify-content: flex-end; gap: 13px; color: var(--muted); font-size: 11px; }
.success-count { color: var(--green); }
.failure-count, .text-danger { color: var(--red); }
.progress-track { height: 7px; margin: 15px 0; overflow: hidden; border-radius: 99px; background: #e9edf2; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.workflow-list { display: grid; gap: 15px; margin: 0; padding: 0; list-style: none; counter-reset: workflow; }
.workflow-list li { position: relative; padding-right: 46px; counter-increment: workflow; }
.workflow-list li::before { content: counter(workflow); position: absolute; right: 0; top: 0; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 900; }
.workflow-list strong, .workflow-list span { display: block; }
.workflow-list span { color: var(--muted); font-size: 12px; }
.permission-note { padding: 14px; color: #81530d; background: var(--amber-soft); border: 1px solid #f1ddb8; border-radius: 11px; }
.settings-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 14px; }
.settings-card { display: grid; grid-template-columns: 48px 1fr 24px; align-items: center; gap: 14px; padding: 21px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: .16s ease; }
.settings-card:hover { transform: translateY(-2px); border-color: #cad2de; }
.settings-card h2 { margin: 0; font-size: 16px; }
.settings-card p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.settings-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; color: var(--accent); background: var(--accent-soft); font-size: 20px; font-weight: 900; }
.guardrail-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 0; }
.guardrail-grid > div { padding: 20px; border-left: 1px solid var(--line); }
.guardrail-grid > div:last-child { border-left: 0; }
.guardrail-grid strong, .guardrail-grid span { display: block; }
.guardrail-grid span { margin-top: 5px; color: var(--muted); font-size: 12px; }

.empty-state { padding: 55px 25px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px; color: var(--accent); background: var(--accent-soft); font-size: 28px; }
.empty-state h3 { margin: 0 0 6px; }
.empty-state p { max-width: 450px; margin: 0 auto 18px; color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 20px; }
.pagination a, .pagination span { min-width: 36px; padding: 6px 10px; text-align: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.pagination .current { color: #fff; border-color: var(--ink); background: var(--ink); }

.login-page { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; background: #fff; }
.login-visual { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; padding: 55px; color: #fff; background: radial-gradient(circle at 20% 20%, #345da2 0, #17243d 38%, #0b1019 78%); }
.login-visual::before, .login-visual::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); }
.login-visual::before { width: 520px; height: 520px; top: -180px; right: -170px; }
.login-visual::after { width: 320px; height: 320px; top: -70px; right: -40px; }
.login-visual h1 { position: relative; max-width: 520px; margin: 0 0 12px; font-size: 37px; line-height: 1.45; }
.login-visual p { position: relative; max-width: 500px; margin: 0; color: #b7c3d6; font-size: 15px; }
.login-panel { display: grid; place-items: center; padding: 35px; }
.login-box { width: min(410px,100%); }
.login-logo { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 24px; border-radius: 16px; color: #17202a; background: linear-gradient(145deg,#f6d367,#dba91e); font-size: 27px; font-weight: 900; }
.login-box h2 { margin: 0 0 7px; font-size: 26px; }
.login-box > p { margin: 0 0 25px; color: var(--muted); }
.login-box .field { margin-bottom: 15px; }
.login-box .button { width: 100%; margin-top: 5px; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: repeat(3,1fr); }
  .product-summary { grid-template-columns: 30px 1fr 120px 100px 30px; }
  .product-summary .product-updated { display: none; }
  .job-summary { grid-template-columns: 50px 1fr 110px 30px; }
  .job-numbers { display: none; }
  .guardrail-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 800px) {
  .sidebar { transform: translateX(110%); transition: transform .22s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .main { margin-right: 0; }
  .mobile-menu { display: block; }
  .topbar { padding: 12px 16px; }
  .content { padding: 22px 14px 50px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .product-summary { grid-template-columns: 28px 1fr 30px; }
  .product-summary .product-price, .product-summary .status { display: none; }
  .quick-grid { grid-template-columns: repeat(2,1fr); }
  .formula-list, .market-grid, .form-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .source-details { grid-template-columns: 1fr; }
  .job-summary { grid-template-columns: 46px 1fr 28px; }
  .job-summary .status { display: none; }
  .step { grid-template-columns: 34px 1fr; }
  .step-expression { grid-column: 2; }
  .default-row { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-panel { min-height: 100vh; padding: 22px; }
}
@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
  .bulk-bar { align-items: stretch; flex-direction: column; }
  .guardrail-grid { grid-template-columns: 1fr; }
  .guardrail-grid > div { border-left: 0; border-bottom: 1px solid var(--line); }
}
