:root {
  --navy-950: #061326;
  --navy-900: #091b33;
  --navy-850: #0d2545;
  --navy-800: #12345e;

  --blue: #2574e8;
  --blue-soft: #edf5ff;

  --cyan: #06b6ca;
  --green: #16a878;
  --green-soft: #e9faf4;

  --orange: #e49a16;
  --red: #de5364;

  --page: #f2f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;

  --text: #17233a;
  --muted: #708097;
  --line: #dae4f0;

  --sidebar: 270px;
  --header: 76px;

  --shadow-sm: 0 5px 18px rgba(27,49,83,.07);
  --shadow-md: 0 16px 42px rgba(27,49,83,.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family:
    "Segoe UI",
    Tahoma,
    Arial,
    sans-serif;
  background: var(--page);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.owner-workspace {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0,1fr) var(--sidebar);
  overflow: hidden;
}

.sidebar {
  grid-column: 2;
  height: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  color: #fff;
  background:
    radial-gradient(
      circle at 50% -10%,
      rgba(37,116,232,.27),
      transparent 35%
    ),
    linear-gradient(
      180deg,
      var(--navy-900),
      var(--navy-950)
    );
  border-left: 1px solid rgba(255,255,255,.08);
  overflow: hidden;
  z-index: 50;
}

.brand {
  min-height: 105px;
  padding: 19px 17px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.09);
}

.brand-logo {
  width: 49px;
  height: 49px;
  flex: 0 0 49px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(135deg,var(--blue),var(--cyan));
  box-shadow: 0 12px 28px rgba(37,116,232,.28);
  font-weight: 900;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong {
  display: block;
  line-height: 1.55;
  font-size: 14px;
}

.brand-copy span {
  display: block;
  margin-top: 3px;
  color: #93a8c8;
  font-size: 11px;
}

.owner-private-badge {
  margin: 14px 13px 7px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border-radius: 11px;
  border: 1px solid rgba(22,168,120,.22);
  background: rgba(22,168,120,.10);
  color: #9de9cb;
  font-size: 11px;
}

.owner-private-badge span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22,168,120,.13);
}

.main-navigation {
  display: grid;
  gap: 5px;
  padding: 9px 11px;
}

.nav-button {
  width: 100%;
  height: 47px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #cedbef;
  padding: 0 12px;
  text-align: right;
  transition: .17s ease;
}

.nav-button:hover {
  background: rgba(255,255,255,.055);
}

.nav-button.active {
  background:
    linear-gradient(
      135deg,
      rgba(37,116,232,.31),
      rgba(6,182,202,.14)
    );
  border-color: rgba(68,155,255,.25);
  color: #fff;
  box-shadow: inset -3px 0 0 var(--cyan);
}

.nav-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,.065);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.09);
}

.system-state {
  display: flex;
  align-items: center;
  gap: 10px;
}

.system-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #36d39b;
  box-shadow: 0 0 0 5px rgba(54,211,155,.10);
}

.system-state strong {
  display: block;
  font-size: 12px;
}

.system-state small {
  display: block;
  margin-top: 2px;
  color: #8095b5;
  font-size: 10px;
}

.workspace-main {
  grid-column: 1;
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: var(--header) minmax(0,1fr);
  overflow: hidden;
}

.workspace-header {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 19px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  box-shadow: 0 3px 15px rgba(24,50,84,.035);
  z-index: 20;
}

.header-title {
  min-width: 0;
  flex: 1;
}

.header-title strong {
  display: block;
  font-size: 20px;
  color: var(--navy-900);
}

.header-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-control,
.header-button {
  height: 41px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.header-button {
  font-weight: 700;
}

.mobile-menu {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--navy-850);
  font-size: 20px;
}

.workspace-content {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.loading-state,
.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5,minmax(0,1fr));
  gap: 10px;
  margin-bottom: 13px;
}

.kpi-card {
  min-width: 0;
  min-height: 102px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.kpi-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 900;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.kpi-card strong {
  display: block;
  margin-top: 7px;
  color: var(--navy-900);
  font-size: 20px;
  direction: ltr;
  text-align: right;
}

.content-grid {
  display: grid;
  grid-template-columns: 1.65fr 1fr;
  gap: 13px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header strong {
  font-size: 13px;
  color: var(--navy-850);
}

.panel-header span {
  margin-right: auto;
  color: var(--muted);
  font-size: 11px;
}

.panel-body {
  padding: 13px;
}

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

.pharmacy-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 14px;
  transition: .17s ease;
}

.pharmacy-card:hover {
  border-color: #91b8f1;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.pharmacy-code {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
}

.pharmacy-card strong {
  display: block;
  margin-top: 11px;
  font-size: 14px;
}

.pharmacy-card p {
  margin: 6px 0 13px;
  color: var(--muted);
  font-size: 11px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 39px;
  border-radius: 10px;
  padding: 0 13px;
  font-weight: 750;
}

.primary-button {
  border: 0;
  background: linear-gradient(135deg,var(--blue),#1559c2);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy-850);
}

.danger-button {
  border: 1px solid #f1cbd1;
  background: #fff3f5;
  color: #b43245;
}

.data-table-wrap {
  width: 100%;
  overflow: auto;
}

.data-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid #e2e9f2;
  text-align: right;
  font-size: 12px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--navy-800);
  color: #fff;
}

.status-pill {
  display: inline-flex;
  min-height: 27px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.status-open {
  background: #fff6e5;
  color: #9c6709;
}

.status-locked {
  background: var(--blue-soft);
  color: #1559c2;
}

.status-complete {
  background: var(--green-soft);
  color: #0d845e;
}

.revenue-workspace {
  height: calc(100vh - 110px);
  min-height: 540px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.revenue-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 12px;
}

.setting-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 15px;
}

.setting-card strong {
  display: block;
}

.setting-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

.toast {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 500;
  min-width: 250px;
  max-width: calc(100vw - 36px);
  padding: 13px 15px;
  border-radius: 12px;
  background: var(--navy-850);
  color: #fff;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(22px);
  pointer-events: none;
  transition: .2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-overlay {
  display: none;
}

@media (max-width: 1200px) {
  :root {
    --sidebar: 235px;
  }

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

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

@media (max-width: 850px) {
  .owner-workspace {
    display: block;
  }

  .workspace-main {
    width: 100%;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: min(84vw,310px);
    transform: translateX(105%);
    transition: .22s ease;
    z-index: 100;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .mobile-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(4,18,36,.57);
    backdrop-filter: blur(2px);
  }

  .mobile-menu {
    display: grid;
    place-items: center;
  }

  .workspace-header {
    padding: 0 10px;
  }

  .header-title strong {
    font-size: 16px;
  }

  .header-title span {
    display: none;
  }

  .header-actions .header-button:last-child {
    display: none;
  }

  .workspace-content {
    padding: 10px;
  }

  .kpi-grid {
    display: flex;
    overflow-x: auto;
  }

  .kpi-card {
    flex: 0 0 170px;
  }

  .content-grid {
    display: block;
  }

  .content-grid .panel {
    margin-bottom: 11px;
  }

  .pharmacy-cards {
    grid-template-columns: 1fr;
  }

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

  .revenue-workspace {
    height: calc(100vh - 98px);
    min-height: 500px;
  }
}

/* ==========================================================
   M.EMAM Workspace Pharmacy Selector
   ========================================================== */

.workspace-revenue-shell {
  width: 100%;
  height: calc(100vh - 108px);
  min-height: 0;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr);

  gap: 10px;
}

.workspace-branch-toolbar {
  min-width: 0;

  display: grid;
  grid-template-columns:
    minmax(190px, 1fr)
    minmax(360px, auto)
    minmax(110px, auto);

  align-items: center;
  gap: 12px;

  padding: 11px 14px;

  border: 1px solid var(--line, #dbe5f1);
  border-radius: 15px;

  background: #fff;
  box-shadow:
    0 5px 18px rgba(25, 48, 82, .07);
}

.workspace-branch-heading span,
.workspace-branch-context span {
  display: block;
  color: #708098;
  font-size: 10px;
}

.workspace-branch-heading strong {
  display: block;
  margin-top: 4px;
  color: #0b2343;
  font-size: 18px;
}

.workspace-branch-context {
  padding: 8px 12px;
  border-radius: 11px;
  background: #f5f9fe;
  text-align: center;
}

.workspace-branch-context strong {
  display: block;
  margin-top: 4px;
  color: #1559c2;
  font-size: 12px;
}

.workspace-branch-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace-branch-selector select {
  height: 42px;
  min-width: 280px;

  border: 1px solid #d3dfed;
  border-radius: 11px;

  padding: 0 12px;

  background: #f8fbff;
  color: #112d51;

  outline: none;
  font-weight: 750;
}

.workspace-branch-selector select:focus {
  border-color: #6096e7;
  box-shadow:
    0 0 0 3px rgba(36, 111, 229, .09);
}

.workspace-branch-nav {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;

  border: 1px solid #d3dfed;
  border-radius: 11px;

  background: #f8fbff;
  color: #15345b;

  font-size: 17px;
  font-weight: 900;
}

.workspace-branch-nav:hover {
  border-color: #86afe9;
  background: #edf4ff;
  color: #1559c2;
}

.workspace-revenue-shell .revenue-workspace {
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
}

.workspace-revenue-shell .revenue-frame {
  width: 100% !important;
  height: 100% !important;
  display: block !important;
  border: 0 !important;
}

@media (max-width: 900px) {
  .workspace-revenue-shell {
    height: calc(100vh - 92px);
  }

  .workspace-branch-toolbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 9px;
  }

  .workspace-branch-heading {
    display: none;
  }

  .workspace-branch-selector {
    width: 100%;
  }

  .workspace-branch-selector select {
    min-width: 0;
    flex: 1;
  }

  .workspace-branch-context {
    display: none;
  }

  .workspace-branch-nav {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }
}

