/* =====================================================================
   Miftah — Application shell
   The side panel lists every page (see "Navigation on the side"); the
   white bar on top carries the page title and the tools, and the page
   sits on the pale canvas. The grouped drawer is for phones. The pill
   bar of the earlier versions (.topnav, "More") is still styled here
   but no longer shown.
   ===================================================================== */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* --- Top bar ---------------------------------------------------------- */
.topbar {
  position: relative;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  flex: none;
  padding-inline: 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: none; }
.brand-mark {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 10px;
  background: var(--accent);
  color: #FFFFFF;
  display: grid;
  place-items: center;
}
.brand-name { display: block; font-size: 16px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
.brand-sub { display: block; font-size: 11px; color: var(--ink-3); line-height: 1.2; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title { display: none; }

/* Pill navigation */
.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-inline: auto;
  min-width: 0;
}
.topnav-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: var(--r-pill);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.topnav-item:hover { background: var(--surface-3); color: var(--ink); }
.topnav-item[aria-current="page"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.topnav-item[aria-current="page"] .count-pill { background: rgba(255, 255, 255, .24); color: var(--accent-ink); }
.topnav-item svg { flex: none; opacity: .7; }
.topnav-item[aria-expanded="true"] { background: var(--surface-3); color: var(--ink); }

.more-wrap { position: relative; display: inline-flex; }
.more-panel { inset-inline-end: 0; width: 270px; padding: 8px; }
.more-group + .more-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
#more-spill[hidden] + .more-group { margin-top: 0; padding-top: 0; border-top: 0; }
.more-group-label { padding: 6px 10px 4px; font-size: 11.5px; font-weight: 600; color: var(--ink-3); }
.more-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  text-align: start;
}
.more-item .nav-ico { color: var(--ink-3); flex: none; }
.more-item:hover { background: var(--accent-soft); color: var(--accent-text); }
.more-item:hover .nav-ico { color: var(--accent); }
.more-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.more-item[aria-current="page"] .nav-ico { color: var(--accent); }

/* Tools */
.topbar-tools { position: relative; margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex: none; }

/* The search is a 38px circle in the flow; the field opens as an overlay
   towards the navigation, so the bar never reflows while typing. */
.search { position: relative; width: 38px; height: 38px; flex: none; z-index: 5; }
.search .input {
  position: absolute;
  top: 0;
  inset-inline-end: 0;
  width: 38px;
  height: 38px;
  padding-inline: 0 38px;   /* no room for the placeholder while collapsed */
  border-radius: var(--r-pill);
  border-color: var(--border);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: width var(--t) var(--ease), background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.search .input:focus {
  width: min(280px, 32vw);
  padding-inline: 14px 38px;
  cursor: text;
  background: var(--surface-2);
}
.search > svg {   /* the magnifier only; result icons stay in their rows */
  position: absolute;
  z-index: 1;
  inset-inline-end: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-2);
  pointer-events: none;
}
.search-results { inset-inline-end: 0; inset-inline-start: auto; width: min(360px, 90vw); }

.notif-wrap { position: relative; }
.notif-badge {
  position: absolute;
  top: -3px; inset-inline-end: -3px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border: 2px solid var(--surface);
  border-radius: 8px;
  background: var(--crit-mark);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

.lang-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
}
.lang-switch button {
  height: 30px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
}
.lang-switch button:hover { color: var(--ink); }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.user-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  transition: background var(--t-fast) var(--ease);
}
.user-btn:hover { background: var(--surface-2); }
.user-btn .avatar { background: var(--accent); color: var(--accent-ink); }
.user-meta { text-align: start; line-height: 1.2; padding-inline-end: 10px; }
.user-meta b { display: block; font-size: 12.5px; font-weight: 600; }
.user-meta span { font-size: 11px; color: var(--ink-3); }

.menu-btn { display: none; }

/* --- Main column ------------------------------------------------------ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 56px;
}
.page-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head h1 { font-size: 28px; font-weight: 500; letter-spacing: -.02em; }
.page-head .page-sub { margin-top: 4px; font-size: 13.5px; color: var(--ink-2); max-width: 62ch; }
.page-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .grow-search { width: min(280px, 100%); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-side-main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.55fr); gap: 16px; align-items: start; }

/* --- Demo ribbon ------------------------------------------------------ */
.demo-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  margin-bottom: 16px;
  border: 1px dashed var(--accent-soft-2);
  border-radius: var(--r);
  background: var(--accent-soft);
  font-size: 12.5px;
  color: var(--good-ink);
}

/* --- Drawer (the grouped menu) ---------------------------------------- */
.sidebar {
  position: fixed;
  z-index: 160;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--sidebar-w);
  max-width: 88vw;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  box-shadow: var(--shadow-modal);
  transform: translateX(calc(var(--dir) * -100%));
  visibility: hidden;   /* off-screen and out of the tab order while closed */
  transition: transform var(--t) var(--ease), visibility 0s linear var(--t);
}
#app.nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--t) var(--ease), visibility 0s; }
@media (min-width: 701px) { .sidebar, .sidebar-backdrop { display: none; } }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding-inline: 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 18px;
}
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 2px; }
.nav-group-label {
  padding: 0 14px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  text-align: start;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item + .nav-item { margin-top: 2px; }
.nav-item:hover { background: var(--accent-soft); color: var(--accent-text); }
.nav-item .nav-ico { flex: none; width: 16px; height: 16px; color: var(--ink-3); }
.nav-item:hover .nav-ico { color: var(--accent); }
.nav-item .nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.nav-item[aria-current="page"] .nav-ico { color: inherit; }
.nav-item[aria-current="page"] .count-pill { background: rgba(255, 255, 255, .24); color: var(--accent-ink); }

.sidebar-foot {
  flex: none;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.plan-card {
  padding: 13px 15px;
  border-radius: var(--r);
  background: var(--accent-deep);
  color: var(--accent-deep-ink);
}
.plan-card .plan-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-card .plan-name { font-size: 13px; font-weight: 700; }
.plan-usage { margin-top: 10px; display: grid; gap: 4px; }
.plan-usage .usage-row { display: flex; justify-content: space-between; font-size: 12px; color: color-mix(in srgb, var(--accent-deep-ink) 72%, transparent); }
.plan-usage .usage-row .mono { color: var(--accent-deep-ink); font-weight: 600; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: color-mix(in srgb, #0B0F0D 45%, transparent);
}

/* --- Navigation on the side (always, since version 18) -----------------
   The drawer becomes a column at the logical start edge (so it sits on
   the right in Arabic), the pills leave the bar and the page title takes
   their place. Phones keep the drawer. As a column it stacks like any
   other part of the page, so the bar's search results, notifications
   and the record drawer open over it. */
@media (min-width: 701px) {
  #app[data-nav="side"] {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
  #app[data-nav="side"] .sidebar {
    display: flex;
    position: static;
    z-index: auto;
    width: auto;
    max-width: none;
    transform: none;
    visibility: visible;
    box-shadow: none;
    transition: none;
  }
  #app[data-nav="side"] .sidebar-backdrop { display: none; }
  #app[data-nav="side"] .topnav,
  #app[data-nav="side"] .topbar > .brand { display: none; }
  #app[data-nav="side"] .topbar-title {
    display: block;
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -.01em;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #app[data-nav="side"] .user-meta { display: block; }
}
@media (min-width: 701px) and (max-width: 1100px) {
  #app[data-nav="side"] .user-meta { display: none; }
}

/* --- Breakpoints ------------------------------------------------------ */
@media (max-width: 1500px) {
  .user-meta { display: none; }
  .user-btn { padding: 3px; }
}

@media (max-width: 1400px) {
  .topbar .brand-sub { display: none; }
  .topnav-item { padding: 0 12px; font-size: 13px; }
}

@media (max-width: 1100px) {
  .topbar { padding-inline: 16px; }
  .topnav-item { padding: 0 10px; }
  .lang-switch button { padding: 0 8px; }
  .grid-main-side, .grid-side-main { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .page { padding: 18px 16px 56px; }
  .page-head h1 { font-size: 24px; }
  .topbar { padding-inline: 14px; gap: 10px; }
  .search .input:focus { width: min(220px, 50vw); }
  .topbar .brand-sub { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
  .topnav { display: none; }
  .menu-btn { display: grid; }
}

@media (max-width: 560px) {
  .lang-switch button { padding: 0 7px; }
  .panel-head h3 { flex-basis: 100%; }   /* the title keeps its own line; the note and the button wrap below */
  .topbar .brand-name { display: none; }
  .search { display: none; }
  .page { padding: 16px 16px 56px; }
}
