@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Tajawal:wght@400;500;700;800&display=swap");

:root {
  --font-sans: "Manrope", "Segoe UI", sans-serif;
  --font-ar: "Tajawal", "Segoe UI", sans-serif;

  --bg: #f4f7fb;
  --bg-soft: #e9eef5;
  --surface: #ffffff;
  --surface-muted: #f6f8fb;
  --surface-strong: #eef3f8;
  --border: #d7e0ea;
  --border-strong: #c3cedb;
  --text: #152033;
  --muted: #5f6f85;

  --primary: #0d6efd;
  --primary-strong: #0b5ed7;
  --primary-soft: rgba(13, 110, 253, 0.12);
  --success: #198754;
  --warning: #d18207;
  --danger: #dc3545;

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;

  --shadow-xs: 0 1px 2px rgba(20, 35, 55, 0.06);
  --shadow-sm: 0 8px 24px rgba(20, 35, 55, 0.08);
  --shadow-md: 0 16px 36px rgba(20, 35, 55, 0.12);

  --topbar-height: 78px;
  --sidebar-width: 292px;

  --transition: 0.2s ease;

  --bs-body-font-family: var(--font-sans);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
}

html[data-theme="dark"] {
  --bg: #0f1723;
  --bg-soft: #141e2d;
  --surface: #182334;
  --surface-muted: #1d2a3d;
  --surface-strong: #243248;
  --border: #2e3d52;
  --border-strong: #3b4f68;
  --text: #eef4fb;
  --muted: #adc0d6;

  --primary: #4f93ff;
  --primary-strong: #3d7fe5;
  --primary-soft: rgba(79, 147, 255, 0.2);
  --success: #2fb87a;
  --warning: #f2b43c;
  --danger: #ff6978;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.22);
  --shadow-sm: 0 10px 24px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 18px 34px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  background:
    radial-gradient(1200px 500px at -10% -20%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 65%),
    radial-gradient(900px 420px at 110% -30%, rgba(25, 135, 84, 0.1), transparent 72%),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
}

html[dir="rtl"] body,
body[dir="rtl"],
body.rtl {
  direction: rtl;
  text-align: right;
  font-family: var(--font-ar);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

h1 {
  font-size: clamp(1.35rem, 1.9vw, 2rem);
}

h2 {
  font-size: clamp(1.15rem, 1.5vw, 1.6rem);
}

h3 {
  font-size: 1.04rem;
}

h4 {
  font-size: 0.95rem;
}

a {
  color: var(--primary);
}

a:hover {
  color: var(--primary-strong);
}

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

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: row-reverse;
}

html[dir="rtl"] .app-shell,
body[dir="rtl"] .app-shell,
body.rtl .app-shell {
  flex-direction: row;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  padding: 1.4rem 1.2rem;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

html[dir="rtl"] .sidebar,
body[dir="rtl"] .sidebar,
body.rtl .sidebar {
  border-inline-start: none;
  border-inline-end: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  padding: 0.35rem 0.3rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

html[dir="rtl"] .brand,
body[dir="rtl"] .brand,
body.rtl .brand {
  flex-direction: row-reverse;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #47b2ff);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 18px color-mix(in srgb, var(--primary) 35%, transparent);
}

.brand-icon {
  width: 21px;
  height: 21px;
}

.brand-title {
  font-size: 1.03rem;
  font-weight: 800;
}

.brand-sub {
  margin-top: 1px;
  font-size: 0.77rem;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0.62rem 0.78rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
  border: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition), background-color var(--transition), transform var(--transition);
  min-width: 0;
}

.nav-link span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.nav-icon {
  color: color-mix(in srgb, var(--muted) 82%, var(--text));
}

.nav-link:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
  background: var(--primary-soft);
}

.nav-link.active {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 20%, transparent);
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
  color: var(--primary);
}

html[dir="rtl"] .nav-link,
body[dir="rtl"] .nav-link,
body.rtl .nav-link {
  flex-direction: row-reverse;
  text-align: right;
}

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

.topbar {
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.45rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.profile-menu {
  position: relative;
  display: flex;
  align-items: center;
  order: 1;
}

.search {
  order: 2;
  flex: 1;
  max-width: 620px;
  min-width: 260px;
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.search-icon {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
}

.search input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 0.24rem 0.2rem;
  font-size: 0.94rem;
}

.search input::placeholder {
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}

html[dir="rtl"] .search,
body[dir="rtl"] .search,
body.rtl .search {
  flex-direction: row-reverse;
  margin-inline-start: 0;
  margin-inline-end: auto;
}

html[dir="rtl"] .search input,
body[dir="rtl"] .search input,
body.rtl .search input {
  text-align: right;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.35rem 0.68rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  color: var(--muted);
}

.ghost,
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 40px;
  border-radius: 12px;
  padding: 0.52rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.ghost,
.btn-outline-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.ghost:hover,
.btn-outline-secondary:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--surface-muted);
}

.primary,
.btn-primary {
  color: #ffffff;
  border-color: color-mix(in srgb, var(--primary) 70%, #163f7b);
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 8px 18px color-mix(in srgb, var(--primary) 34%, transparent);
}

.primary:hover,
.btn-primary:hover {
  transform: translateY(-1px);
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary-strong), var(--primary));
}

.button-small,
.btn-sm {
  min-height: 34px;
  border-radius: 10px;
  padding: 0.37rem 0.68rem;
  font-size: 0.8rem;
}

.link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
}

.link:hover {
  color: var(--primary-strong);
  text-decoration: underline;
}

.hint-trigger,
.profile-trigger {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  padding: 0;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: auto;
  min-width: 230px;
  max-width: min(320px, calc(100vw - 16px));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-md);
  padding: 0.55rem;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 80;
}

.profile-menu.open .profile-dropdown {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.profile-dropdown.align-left {
  left: 0;
  right: auto;
}

.profile-dropdown.align-right {
  left: auto;
  right: 0;
}

.profile-header {
  padding: 0.3rem 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.45rem;
}

.profile-email {
  font-size: 0.8rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.profile-items {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dropdown-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  text-align: start;
  padding: 0.44rem 0.58rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  font: inherit;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.dropdown-item:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 28%, var(--border));
  background: var(--primary-soft);
}

.hint-panel {
  position: fixed;
  top: calc(var(--topbar-height) + 10px);
  right: 22px;
  width: min(370px, calc(100vw - 44px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.95rem;
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition);
}

.hint-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

html[dir="rtl"] .hint-panel,
body[dir="rtl"] .hint-panel,
body.rtl .hint-panel {
  right: auto;
  left: 22px;
}

.hint-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.hint-title {
  font-size: 0.96rem;
  font-weight: 700;
}

.hint-summary {
  color: var(--muted);
  font-size: 0.84rem;
}

.hint-section + .hint-section {
  margin-top: 0.75rem;
}

.hint-section-title {
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hint-list {
  margin: 0.42rem 0 0;
  padding-inline-start: 1rem;
  display: grid;
  gap: 0.3rem;
  font-size: 0.84rem;
}

.content {
  padding: 1.2rem 1.45rem 2rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.page-header .actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.page-header p {
  margin: 0.32rem 0 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 32%, var(--border));
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.22rem 0.62rem;
  margin-bottom: 0.45rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  align-items: start;
}

.invoice-detail-grid {
  grid-template-columns: 1fr;
}

.invoice-detail-grid > .card {
  width: 100%;
}

.stats-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(min(175px, 100%), 1fr));
}

.card,
.stat-card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card {
  padding: 1.1rem;
}

.card:hover {
  border-color: color-mix(in srgb, var(--primary) 16%, var(--border));
}

.card > h3,
.card > h4 {
  margin-bottom: 0.72rem;
}

.form-card {
  position: relative;
}

.form-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: linear-gradient(90deg, var(--primary), #42b8ff 45%, #3bc28b);
}

.filter-card form,
.inline-form {
  margin-top: 0;
}

.form-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.36rem;
  min-width: 0;
}

.form-field-wide {
  grid-column: 1 / -1;
}

.form-field label,
.form-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0;
}

.form-field input,
.form-field select,
.form-field textarea,
.form-control,
.form-select,
textarea {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  padding: 0.64rem 0.78rem;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
  text-align: start;
}

.form-field textarea,
textarea {
  min-height: 110px;
  resize: vertical;
}

.form-field select[multiple],
select[multiple] {
  min-height: 126px;
}

.form-field input::placeholder,
.form-field textarea::placeholder,
textarea::placeholder,
.form-control::placeholder {
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.form-control:focus,
.form-select:focus,
textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 52%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.form-field input[type="file"] {
  padding: 0.5rem 0.65rem;
  border-style: dashed;
  box-shadow: none;
}

.form-field input[type="file"]::file-selector-button {
  margin-inline-end: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 9px;
  padding: 0.32rem 0.54rem;
  cursor: pointer;
}

.form-actions {
  margin-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.58rem;
  flex-wrap: wrap;
}

.form-message {
  color: var(--muted);
  font-size: 0.8rem;
}

.form-message.error,
.error {
  color: var(--danger);
}

.form-message.success {
  color: var(--success);
}

.muted {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.section-title {
  margin: 1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 0.9rem 0;
}

.section-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.55rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.table {
  width: 100%;
  min-width: 760px;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
}

.table th,
.table td {
  padding: 0.74rem 0.82rem;
  border-bottom: 1px solid var(--border);
  text-align: start;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.table th {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  background: var(--surface-muted);
}

.table tbody tr:nth-child(odd) {
  background: color-mix(in srgb, var(--surface-muted) 55%, var(--surface));
}

.table tbody tr:hover {
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.item-editor {
  margin-top: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.item-editor h4 {
  margin: 0;
  font-size: 0.79rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.item-table {
  min-width: 1000px;
}

.item-table td,
.item-table th {
  white-space: nowrap;
}

.table-input {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.48rem 0.62rem;
  font-size: 0.92rem;
}

.table-input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 52%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.item-table td:first-child .table-input {
  min-width: 280px;
}

.item-table td:nth-child(2) .table-input,
.item-table td:nth-child(3) .table-input {
  min-width: 130px;
}

.invoice-detail-grid .table {
  min-width: 720px;
}

.invoice-detail-grid .item-table {
  min-width: 880px;
}

.invoice-detail-grid .item-table td:first-child .table-input {
  min-width: 360px;
}

.item-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

html[dir="rtl"] .item-actions,
body[dir="rtl"] .item-actions,
body.rtl .item-actions {
  justify-content: flex-start;
}

.info-list {
  display: flex;
  flex-direction: column;
  gap: 0.24rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
}

.info-row:last-child {
  border-bottom: none;
}

.info-row-wide {
  flex-direction: column;
  gap: 0.28rem;
  align-items: flex-start;
}

.info-label {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.info-value {
  font-weight: 650;
  text-align: end;
  max-width: 68%;
  overflow-wrap: anywhere;
}

.info-row-wide .info-value {
  max-width: none;
  text-align: start;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.list.compact {
  gap: 0.35rem;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.66rem;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  min-width: 0;
}

.list-item > div {
  min-width: 0;
}

.list.compact .list-item {
  padding: 0.46rem 0.58rem;
}

.title {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0.62rem;
}

.timeline-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 0.58rem;
  align-items: flex-start;
}

.timeline .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 0.44rem;
  background: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 20%, transparent);
}

.notes-list {
  margin-top: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.note-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 0.6rem 0.72rem;
}

.note-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 650;
}

.note-body {
  margin-top: 0.34rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 0.65rem;
}

.gallery-group + .gallery-group {
  margin-top: 0.75rem;
}

.group-title {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.45rem;
}

.photo-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.45rem;
  box-shadow: var(--shadow-xs);
}

.photo-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 9px;
}

.photo-card .caption {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.3rem 0.58rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--border));
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-new,
.status-open,
.status-draft,
.status-sent,
.status-invoiced,
.status-active,
.status-default,
.status-pending {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  border-color: color-mix(in srgb, var(--primary) 34%, var(--border));
}

.status-in_progress,
.status-partially_paid,
.status-waiting_parts,
.status-overdue {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 16%, transparent);
  border-color: color-mix(in srgb, var(--warning) 33%, var(--border));
}

.status-paid,
.status-completed,
.status-approved {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 16%, transparent);
  border-color: color-mix(in srgb, var(--success) 34%, var(--border));
}

.status-cancelled,
.status-rejected,
.status-failed {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  border-color: color-mix(in srgb, var(--danger) 33%, var(--border));
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.pagination-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.alert {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
}

.alert.success {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 36%, var(--border));
  background: color-mix(in srgb, var(--success) 10%, transparent);
}

.switch-row {
  margin-top: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0.62rem 0.72rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 50%, transparent);
  transition: background-color var(--transition);
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  transition: transform var(--transition);
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

html[dir="rtl"] .switch input:checked + .switch-slider::before,
body[dir="rtl"] .switch input:checked + .switch-slider::before,
body.rtl .switch input:checked + .switch-slider::before {
  transform: translateX(-20px);
}

.demo-credentials {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.45rem;
}

.code-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  padding: 0.32rem 0.56rem;
  font-size: 0.76rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.payload {
  margin: 0;
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.72rem;
  color: var(--muted);
}

.stat-card {
  padding: 0.85rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.stat-label,
.stat .label,
.label {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value,
.stat .value,
.value {
  font-size: clamp(1.1rem, 2vw, 1.68rem);
  line-height: 1.2;
  font-weight: 800;
  color: var(--text);
}

.stat-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 0.72rem;
  align-items: end;
  min-height: 180px;
}

.bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.bar-fill {
  width: 100%;
  max-width: 70px;
  min-height: 4px;
  border-radius: 10px 10px 6px 6px;
  background: linear-gradient(180deg, var(--primary), #3db7ff);
  box-shadow: 0 10px 18px color-mix(in srgb, var(--primary) 25%, transparent);
}

.bar-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bar-value {
  font-size: 0.77rem;
  font-weight: 700;
}

.line-chart {
  width: 100%;
  height: 130px;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.finance-hero {
  padding: 1.2rem;
  overflow: hidden;
}

.finance-hero-top {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.finance-kpi {
  min-width: min(280px, 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
  padding: 0.7rem 0.8rem;
}

.finance-header .actions {
  margin-inline-start: auto;
}

.tabs {
  margin-top: 0.3rem;
}

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.tab-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.38rem 0.72rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background-color var(--transition);
}

.tab-button:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 36%, var(--border));
}

.tab-button.active {
  color: #ffffff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.dual-bar-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.72rem;
  align-items: end;
  min-height: 180px;
}

.bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.bar-pair {
  width: 100%;
  height: 130px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.34rem;
}

.dual-bar-chart .bar-fill {
  flex: 1;
  max-width: 34px;
}

.dual-bar-chart .bar-in {
  background: linear-gradient(180deg, var(--success), #63dca9);
  box-shadow: 0 10px 18px color-mix(in srgb, var(--success) 30%, transparent);
}

.dual-bar-chart .bar-out {
  background: linear-gradient(180deg, var(--warning), #f1be56);
  box-shadow: 0 10px 18px color-mix(in srgb, var(--warning) 30%, transparent);
}

.finance-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-inline-end: 0.3rem;
}

.legend-dot.in {
  background: var(--success);
}

.legend-dot.out {
  background: var(--warning);
}

.mobile-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.mobile-card {
  padding: 0.95rem;
}

.mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.mobile-meta {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.mobile-section {
  margin-top: 0.7rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.mobile-section summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.mobile-section summary::-webkit-details-marker {
  display: none;
}

.mobile-section > form {
  margin-top: 0.55rem;
}

.upload-progress {
  margin: 0.65rem 0;
}

.upload-progress .progress-bar {
  position: relative;
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 25%, transparent);
  overflow: hidden;
}

.upload-progress .progress-bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--progress, 0%);
  background: linear-gradient(90deg, var(--primary), #36c2a9);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.upload-progress .progress-text {
  margin-top: 0.34rem;
  font-size: 0.76rem;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.4rem;
}

.auth-card {
  width: min(450px, 100%);
  padding: 1.4rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  margin-top: 0.55rem;
}

.auth-card form {
  margin-top: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.72rem;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.34rem;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.auth-card input {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.62rem 0.75rem;
}

.auth-card input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--primary) 52%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.auth-card .primary {
  width: 100%;
}

.lang-actions {
  margin-top: 0.7rem;
  display: flex;
  justify-content: center;
}

.totals,
.meta,
.header {
  color: var(--muted);
}

html[dir="rtl"] .page-header,
html[dir="rtl"] .info-row,
html[dir="rtl"] .note-meta,
html[dir="rtl"] .mobile-header,
html[dir="rtl"] .chart-axis,
html[dir="rtl"] .pagination,
body[dir="rtl"] .page-header,
body[dir="rtl"] .info-row,
body[dir="rtl"] .note-meta,
body[dir="rtl"] .mobile-header,
body[dir="rtl"] .chart-axis,
body[dir="rtl"] .pagination,
body.rtl .page-header,
body.rtl .info-row,
body.rtl .note-meta,
body.rtl .mobile-header,
body.rtl .chart-axis,
body.rtl .pagination {
  direction: rtl;
}

html[dir="rtl"] .page-header h1,
html[dir="rtl"] .page-header h2,
html[dir="rtl"] .page-header h3,
html[dir="rtl"] .page-header p,
body[dir="rtl"] .page-header h1,
body[dir="rtl"] .page-header h2,
body[dir="rtl"] .page-header h3,
body[dir="rtl"] .page-header p,
body.rtl .page-header h1,
body.rtl .page-header h2,
body.rtl .page-header h3,
body.rtl .page-header p {
  text-align: right;
}

html[dir="rtl"] .form-field label,
html[dir="rtl"] .section-title,
html[dir="rtl"] .group-title,
html[dir="rtl"] .stat-label,
html[dir="rtl"] .bar-label,
html[dir="rtl"] .info-label,
body[dir="rtl"] .form-field label,
body[dir="rtl"] .section-title,
body[dir="rtl"] .group-title,
body[dir="rtl"] .stat-label,
body[dir="rtl"] .bar-label,
body[dir="rtl"] .info-label,
body.rtl .form-field label,
body.rtl .section-title,
body.rtl .group-title,
body.rtl .stat-label,
body.rtl .bar-label,
body.rtl .info-label {
  text-transform: none;
  letter-spacing: 0;
}

html[dir="rtl"] .form-field input,
html[dir="rtl"] .form-field textarea,
html[dir="rtl"] .form-field select,
body[dir="rtl"] .form-field input,
body[dir="rtl"] .form-field textarea,
body[dir="rtl"] .form-field select,
body.rtl .form-field input,
body.rtl .form-field textarea,
body.rtl .form-field select {
  text-align: right;
}

html[dir="rtl"] .table,
body[dir="rtl"] .table,
body.rtl .table {
  direction: rtl;
}

html[dir="rtl"] .table th,
html[dir="rtl"] .table td,
body[dir="rtl"] .table th,
body[dir="rtl"] .table td,
body.rtl .table th,
body.rtl .table td {
  text-align: right;
}

html[dir="rtl"] .info-row {
  flex-direction: row-reverse;
}

html[dir="rtl"] .info-row-wide {
  flex-direction: column;
}

html[dir="rtl"] .info-value {
  text-align: start;
}

html[dir="rtl"] .form-actions,
body[dir="rtl"] .form-actions,
body.rtl .form-actions {
  justify-content: flex-start;
}

html[dir="rtl"] .page-header .actions,
body[dir="rtl"] .page-header .actions,
body.rtl .page-header .actions {
  margin-inline-end: auto;
}

html[dir="rtl"] .profile-menu,
body[dir="rtl"] .profile-menu,
body.rtl .profile-menu {
  order: 2;
}

html[dir="rtl"] .search,
body[dir="rtl"] .search,
body.rtl .search {
  order: 1;
}

@media (max-width: 1400px) {
  .grid {
    grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr));
  }
}

@media (max-width: 1199px) {
  .sidebar {
    display: none;
  }

  .topbar {
    padding: 0.9rem 1rem;
  }

  .content {
    padding: 1rem;
  }
}

@media (max-width: 899px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .profile-menu {
    align-self: flex-end;
  }

  html[dir="rtl"] .profile-menu,
  body[dir="rtl"] .profile-menu,
  body.rtl .profile-menu {
    align-self: flex-start;
  }

  .search {
    max-width: none;
    min-width: 100%;
    margin-inline: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .table {
    min-width: 660px;
  }

  .item-table {
    min-width: 940px;
  }

  .invoice-detail-grid .item-table {
    min-width: 940px;
  }

  .info-row,
  .list-item,
  .mobile-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .info-value {
    text-align: start;
    max-width: none;
  }

  .pagination {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 575px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 1rem;
  }

  .card {
    padding: 0.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
