:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #263342;
  --muted: #8392a5;
  --line: #e9eef4;
  --blue: #1f7bcf;
  --blue-dark: #176bb5;
  --sky: #4aa8ec;
  --teal: #27c2ba;
  --orange: #f7a600;
  --violet: #7765e3;
  --red: #ef5b6f;
  --green: #29b678;
  --gold: #c7a337;
  --gold-2: #ead074;
  --shadow: 0 10px 28px rgba(33, 48, 70, .07);
  --sidebar: 178px;
  font-family: Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #1372bd, #0f4f92);
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(14, 58, 101, .22);
  padding: 22px;
}
.login-logo,
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.login-logo { margin-bottom: 18px; }
.login-logo img,
.brand img {
  object-fit: contain;
  background: #000;
}
.login-logo img {
  width: 58px;
  height: 58px;
  border-radius: 8px;
}
.login-logo h1,
.brand h1 { margin: 0; }
.login-logo h1 { font-size: 22px; }
.login-logo p,
.brand p {
  margin: 4px 0 0;
  font-size: 12px;
}
.login-logo p { color: var(--muted); }
.login-form {
  display: grid;
  gap: 12px;
}
.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
  direction: rtl;
}
.sidebar {
  position: fixed;
  inset: 0 0 0 auto;
  width: var(--sidebar);
  background: linear-gradient(180deg, #2384d5, #176eba);
  color: #fff;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: -8px 0 24px rgba(25, 101, 168, .18);
  z-index: 10;
}
.brand {
  justify-content: center;
  min-height: 74px;
  padding: 2px 0 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .18);
}
.brand img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}
.brand h1 {
  color: #fff;
  font-size: 15px;
  line-height: 1.2;
}
.brand p { color: rgba(255, 255, 255, .75); }
.nav {
  display: grid;
  gap: 4px;
}
.nav-btn {
  width: 100%;
  min-height: 39px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: rgba(255, 255, 255, .86);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  text-align: right;
  font-weight: 700;
}
.nav-btn:hover,
.nav-btn.active {
  background: rgba(255, 255, 255, .14);
  color: #fff;
}
.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: #fff;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, .12);
}
.nav-icon svg,
.quick-icon svg,
.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side-foot {
  margin-top: auto;
  color: rgba(255, 255, 255, .74);
  font-size: 11px;
  line-height: 1.6;
  background: rgba(255, 255, 255, .1);
  border-radius: 6px;
  padding: 10px;
}

.main {
  min-width: 0;
  min-height: 100vh;
  margin-right: var(--sidebar);
}
.topbar {
  min-height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto minmax(210px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 8px 18px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.top-tools {
  display: flex;
  align-items: center;
  direction: ltr;
}
.icon-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 4px;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
}
.icon-button .nav-icon {
  width: auto;
  height: auto;
  background: transparent;
}
.crumb {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.title h2 {
  margin: 2px 0 0;
  font-size: 15px;
  line-height: 1.3;
  color: #4b6f98;
}
.title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}
.toolbar {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.content {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 14px 18px 30px;
}
.banner {
  min-height: 34px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.btn,
.field {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 4px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  font-weight: 700;
}
.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn.danger {
  background: #fff0f3;
  border-color: #f3b9c2;
  color: #c2374b;
}
.btn.dark {
  background: #263342;
  border-color: #263342;
  color: #fff;
}
.field {
  padding: 7px 9px;
  min-width: 0;
}
.status {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.status.gold { color: #9b6a00; background: #fff4d9; }
.status.green { color: #18845a; background: #eaf8f2; }
.status.red { color: #c2374b; background: #fff0f3; }
.status.blue { color: var(--blue); background: #e9f4ff; }

.view { display: none; }
.view.active { display: block; }
.period-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  width: fit-content;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}
.period-btn {
  min-width: 92px;
  min-height: 35px;
  border: 0;
  border-left: 1px solid var(--line);
  background: #fff;
  color: #7b8794;
  font-weight: 700;
}
.period-btn:last-child { border-left: 0; }
.period-btn.active {
  background: var(--blue);
  color: #fff;
}
.sales-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.sales-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: #5d7894;
  font-weight: 800;
  padding: 8px 16px;
}
.sales-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.sales-page,
.purchases-page { display: none; }
.sales-page.active,
.purchases-page.active { display: block; }
.panel-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(145px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.quick-card {
  min-height: 58px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  color: #5b8fc4;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.quick-card:hover {
  transform: translateY(-2px);
  border-color: #b9d9f2;
  box-shadow: 0 14px 30px rgba(33, 48, 70, .11);
}
.quick-card::after {
  content: "+";
  color: #9ca9b7;
  font-size: 21px;
  line-height: 1;
}
.quick-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  background: #eef7ff;
  color: var(--blue);
}
.quick-card strong {
  color: #5d7894;
  font-size: 13px;
  text-align: right;
  line-height: 1.35;
  flex: 1;
  margin-inline: 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.metric-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  min-height: 88px;
  padding: 13px;
  display: grid;
  align-content: center;
  position: relative;
  overflow: hidden;
}
.metric-card.feature {
  grid-column: span 4;
  min-height: 170px;
  padding: 0;
  color: #fff;
  align-content: stretch;
}
.metric-card.feature::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 104px;
  background: #fff;
}
.metric-card.feature .metric-head {
  min-height: 68px;
  padding: 15px 18px 8px;
  display: grid;
  align-content: center;
  text-align: center;
  z-index: 1;
}
.metric-card.feature .metric-title {
  color: rgba(255, 255, 255, .95);
  font-weight: 800;
}
.metric-card.feature .metric-value {
  color: #fff;
  margin-top: 4px;
  text-align: center;
  font-size: 19px;
}
.metric-card.feature.blue { background: var(--sky); }
.metric-card.feature.teal { background: var(--teal); }
.metric-card.feature.orange { background: var(--orange); }
.metric-card.feature .metric-lines {
  z-index: 1;
  margin: 4px 16px 14px;
  background: #fff;
  color: #7d8998;
  border-radius: 4px;
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow: 0 10px 22px rgba(44, 69, 97, .08);
}
.metric-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #eef2f6;
  padding-bottom: 7px;
}
.metric-line:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.metric-line b {
  color: #536171;
  direction: ltr;
  font-size: 11px;
}
.metric-card.compact {
  grid-column: span 3;
}
.metric-card.compact .metric-title {
  color: var(--muted);
  font-weight: 800;
}
.metric-card.compact .metric-value {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 900;
  direction: ltr;
  text-align: right;
}
.metric-card.compact .metric-accent {
  position: absolute;
  inset-inline-end: 12px;
  bottom: 10px;
  color: rgba(31, 123, 207, .13);
}
.metric-card.compact .metric-accent svg {
  width: 34px;
  height: 34px;
  stroke-width: 2.4;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, .58fr);
  gap: 16px;
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.panel-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  color: #536171;
}
.panel-body { padding: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.wide-table { min-width: 1680px; }
th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}
th {
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}
td { color: #5c6877; }
.amount {
  direction: ltr;
  text-align: right;
  font-weight: 900;
  white-space: nowrap;
}
.amount.positive { color: #18845a; }
.amount.negative { color: #c2374b; }
.table-scroll { overflow-x: auto; }
.table-action {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 11px;
}

.accounts-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.account-table .total-row td {
  background: #f6fbff;
  color: var(--ink);
  font-weight: 900;
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.report-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 13px;
  background: #fff;
}
.report-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
}
.report-card ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 7px;
}
.report-card li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed #e3e9ef;
  padding-bottom: 6px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 49, 64, .38);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}
.modal-card {
  width: min(720px, 100%);
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .18);
  overflow: hidden;
}
.toast {
  position: fixed;
  left: 22px;
  bottom: 22px;
  background: #263342;
  color: #fff;
  padding: 12px 14px;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(14px);
  transition: .18s ease;
  z-index: 30;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1120px) {
  :root { --sidebar: 162px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card.feature { grid-column: span 12; }
  .metric-card.compact { grid-column: span 6; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  :root { --sidebar: 0px; }
  html { background: #eef5f9; }
  body {
    overflow-x: hidden;
    background: #eef5f9;
    font-size: 12px;
  }
  .login-screen {
    padding: 14px;
  }
  .login-card {
    padding: 18px;
  }
  .app-shell {
    min-height: 100vh;
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }
  .main {
    margin-right: 0;
    min-height: 100vh;
  }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: calc(70px + env(safe-area-inset-bottom));
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    background: rgba(31, 123, 207, .98);
    box-shadow: 0 -10px 28px rgba(25, 101, 168, .22);
  }
  .brand,
  .side-foot {
    display: none;
  }
  .nav {
    height: 100%;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar {
    display: none;
  }
  .nav-btn {
    flex: 0 0 86px;
    min-height: 54px;
    border-radius: 10px;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    gap: 4px;
    padding: 6px 4px;
    font-size: 10.5px;
    line-height: 1.25;
  }
  .nav-icon {
    width: 24px;
    height: 24px;
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 8;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: calc(env(safe-area-inset-top) + 10px) 10px 10px;
    box-shadow: 0 8px 22px rgba(31, 64, 92, .08);
  }
  .top-tools {
    display: none;
  }
  .title h2 {
    font-size: 16px;
  }
  .title p {
    font-size: 11px;
  }
  .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }
  .toolbar .field,
  .toolbar .btn {
    width: 100%;
  }
  .content {
    width: 100%;
    padding: 10px 10px 92px;
  }
  .banner {
    min-height: auto;
    align-items: stretch;
    flex-direction: column;
    border-radius: 8px;
  }
  .period-tabs {
    width: 100%;
    overflow-x: auto;
  }
  .period-btn {
    min-width: 78px;
    flex: 1;
    font-size: 11px;
  }
  .sales-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .sales-tab {
    min-height: 40px;
    padding: 8px;
    font-size: 12px;
  }
  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  .quick-card {
    min-height: 78px;
    justify-content: center;
    flex-direction: column;
    gap: 7px;
    padding: 10px;
    text-align: center;
  }
  .quick-card::after {
    display: none;
  }
  .quick-card strong {
    margin: 0;
    text-align: center;
    font-size: 12px;
  }
  .metrics {
    gap: 10px;
  }
  .metric-card.feature,
  .metric-card.compact {
    grid-column: span 12;
  }
  .metric-card.compact {
    min-height: 76px;
  }
  .grid-2,
  .accounts-grid,
  .reports-grid {
    grid-template-columns: 1fr;
  }
  .panel {
    border-radius: 8px;
    margin-bottom: 12px;
  }
  .panel-head {
    align-items: stretch;
    flex-direction: column;
    padding: 11px;
  }
  .panel-head .btn {
    width: 100%;
  }
  .panel-body {
    padding: 10px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .table-scroll {
    margin-inline: -10px;
    padding-inline: 10px;
  }
  table {
    min-width: 680px;
    font-size: 11px;
  }
  table.wide-table {
    min-width: 1500px;
  }
  th,
  td {
    padding: 9px 10px;
  }
  .modal {
    align-items: end;
    padding: 0;
  }
  .modal-card {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
  }
  .modal-card .panel-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
  }
  .toast {
    right: 10px;
    left: 10px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    text-align: center;
  }
}
