:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --ink: #17211d;
  --muted: #68756f;
  --line: #dbe2dd;
  --primary: #136f63;
  --primary-dark: #0f5149;
  --credit: #0f766e;
  --debit: #b45309;
  --danger: #b42318;
  --balanced: #59656f;
  --shadow: 0 18px 45px rgba(24, 39, 33, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(19, 111, 99, 0.08), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: "Tajawal", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #17211d;
  color: #fff;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: #d6efe8;
  color: var(--primary);
}

.brand-mark svg,
.icon svg {
  width: 1.2em;
  height: 1.2em;
  fill: currentColor;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: #b9c7c1;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-link,
.ghost-button,
.primary-button,
.text-button,
.back-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  min-height: 44px;
  transition: 160ms ease;
}

.nav-link {
  justify-content: flex-start;
  padding: 0 14px;
  background: transparent;
  color: #cbd8d2;
  min-width: 0;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: #d8e2dd;
  font-size: 0.92rem;
  line-height: 1.7;
}

.sidebar-note p {
  margin: 8px 0 0;
}

.main {
  width: min(1180px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
}

.top-actions,
.filters,
.action-row,
.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.sync-status.loading {
  color: var(--debit);
  border-color: #f1d7a8;
  background: #fff8e8;
}

.sync-status.success {
  color: var(--credit);
  border-color: #bde7dd;
  background: #effbf7;
}

.sync-status.error {
  color: var(--danger);
  border-color: #f1c3bd;
  background: #fff5f3;
}

.date-filter-bar {
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.date-filter-bar label {
  min-width: 170px;
  flex: 1;
}

.primary-button {
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button,
.back-button {
  padding: 0 16px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost-button:hover,
.back-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.text-button {
  min-height: auto;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #f1c3bd;
  border-radius: var(--radius);
  background: #fff5f3;
  color: var(--danger);
  font-weight: 700;
}

.danger-zone {
  display: flex;
  justify-content: flex-start;
  margin: -4px 0 16px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dashboard-hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  align-items: center;
  gap: 22px;
  min-height: 210px;
  margin-bottom: 18px;
  padding: 26px;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(19, 111, 99, 0.92), rgba(23, 33, 29, 0.96)),
    url("data:image/svg+xml,%3Csvg width='960' height='360' viewBox='0 0 960 360' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.18' stroke-width='2'%3E%3Cpath d='M48 266h864M88 210h784M128 154h704M168 98h624'/%3E%3Cpath d='M208 276V78M352 276V78M496 276V78M640 276V78M784 276V78'/%3E%3C/g%3E%3Cg fill='%23ffffff' fill-opacity='.25'%3E%3Ccircle cx='208' cy='210' r='7'/%3E%3Ccircle cx='352' cy='154' r='7'/%3E%3Ccircle cx='496' cy='198' r='7'/%3E%3Ccircle cx='640' cy='112' r='7'/%3E%3Ccircle cx='784' cy='172' r='7'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
  color: #fff;
  box-shadow: var(--shadow);
}

.dashboard-hero .eyebrow {
  color: #abf0df;
}

.dashboard-hero h2 {
  max-width: 650px;
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.25;
}

.hero-visual {
  display: grid;
  gap: 12px;
}

.hero-visual span {
  display: block;
  height: 42px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
}

.hero-visual span:nth-child(2) {
  width: 72%;
}

.hero-visual span:nth-child(3) {
  width: 88%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.account-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
}

.stat-card span,
.balance-box span,
.meta-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.55rem;
}

.content-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.activity-list {
  display: grid;
  gap: 10px;
}

.activity-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.activity-item p {
  margin-bottom: 3px;
  font-weight: 700;
}

.activity-item small {
  color: var(--muted);
}

.accent-panel {
  background: #fffaf0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.toolbar p {
  color: var(--muted);
  margin-bottom: 0;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box .icon {
  position: absolute;
  right: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

.search-box input {
  width: min(360px, 70vw);
  padding-right: 40px;
}

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.account-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  text-align: right;
}

.account-card button {
  justify-self: start;
}

.account-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.account-top h3 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.account-top p,
.account-card small {
  margin: 0;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf7ff;
  color: #155e75;
  font-size: 0.86rem;
  font-weight: 700;
}

.status-debtor {
  background: #fff4df;
  color: var(--debit);
}

.status-creditor {
  background: #dff8f3;
  color: var(--credit);
}

.status-balanced {
  background: #edf0f2;
  color: var(--balanced);
}

.money-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.money-row strong {
  font-size: 1.25rem;
}

.detail-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  margin: 16px 0;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.detail-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.balance-box {
  min-width: 230px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.balance-box strong {
  display: block;
  margin: 7px 0;
  font-size: 1.65rem;
}

.action-row {
  margin-bottom: 16px;
}

.action-row .primary-button {
  min-width: 150px;
}

.transactions-panel {
  padding: 0;
  overflow: hidden;
}

.transactions-panel .panel-header {
  padding: 18px 18px 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  text-align: right;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f9faf8;
}

.modal {
  width: min(520px, calc(100vw - 24px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(15, 22, 19, 0.48);
}

.modal-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  background: var(--surface-soft);
  color: var(--ink);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.check-line {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
}

.check-line input {
  width: 18px;
  min-height: 18px;
}

.rate-preview {
  padding: 12px;
  border-radius: var(--radius);
  background: #eef8f4;
  color: var(--primary-dark);
  font-weight: 700;
}

.hidden {
  display: none;
}

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

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
    width: 100%;
    overflow: hidden;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-link {
    justify-content: center;
    min-height: 42px;
    padding: 0 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    gap: 4px;
  }

  .nav-link .icon {
    flex: 0 0 auto;
  }

  .sidebar-note {
    display: none;
  }

  .dashboard-hero,
  .content-grid,
  .detail-header {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .accounts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  body {
    background: var(--bg);
  }

  .main {
    padding: 14px 12px 24px;
  }

  .sidebar {
    gap: 14px;
  }

  .brand {
    align-items: center;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .topbar,
  .toolbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .filters,
  .action-row,
  .date-filter-bar {
    width: 100%;
  }

  .top-actions > *,
  .filters > *,
  .action-row > *,
  .date-filter-bar > *,
  .search-box input {
    width: 100%;
  }

  .dashboard-hero {
    min-height: auto;
    padding: 18px;
  }

  .dashboard-hero h2 {
    font-size: 1.55rem;
  }

  .hero-visual {
    display: none;
  }

  .stats-grid,
  .accounts-grid {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }

  .panel,
  .stat-card,
  .account-card,
  .detail-header,
  .date-filter-bar {
    box-shadow: none;
  }

  table {
    min-width: 680px;
  }

  .table-wrap {
    width: 100%;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th,
  td {
    padding: 11px 12px;
  }

  .row-actions {
    gap: 6px;
  }
}
