/* ============================================================
   APP — base, layout, components
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  background: var(--color-app-bg);
  color: var(--color-charcoal);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { font-family: var(--font-heading); margin: 0; color: var(--color-ink); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
.num, .ltr-num { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* =========================================================
   App shell
   ========================================================= */
.app-shell  { display: flex; height: 100vh; overflow: hidden; }
.app-main   { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--color-app-bg); }
.app-content{ flex: 1; overflow: auto; padding: 28px 32px; }

/* =========================================================
   Sidebar
   ========================================================= */
.side {
  width: 248px; flex-shrink: 0;
  background: var(--color-app-panel);
  display: flex; flex-direction: column;
  transition: width 200ms ease-out;
}
[dir="rtl"] .side { border-left:  1px solid var(--color-app-border); }
[dir="ltr"] .side { border-right: 1px solid var(--color-app-border); }

.side .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--color-app-border);
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--color-ink);
}
.side .brand-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.side-section-head {
  padding: 14px 16px 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--color-stone); font-weight: 600;
}
.side-list { padding: 4px 0; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 0 8px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--color-charcoal);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.nav-item:hover { background: var(--color-app-hover); }
.nav-item.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
}
.nav-item .nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-inline-start: auto;
  background: var(--color-primary); color: #fff;
  font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 9999px;
}

.side .side-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--color-app-border);
  font-size: 12px; color: var(--color-stone);
}

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  height: 64px; flex-shrink: 0;
  background: var(--color-app-panel);
  border-bottom: 1px solid var(--color-app-border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
}
.topbar h1 {
  font-size: 18px; font-weight: 700; color: var(--color-ink);
  font-family: var(--font-heading);
}
.topbar .topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar .topbar-user-text { display: flex; flex-direction: column; line-height: 1.1; }
.topbar .topbar-user-text .name { font-size: 13px; font-weight: 600; color: var(--color-ink); }
.topbar .topbar-user-text .role { font-size: 12px; color: var(--color-stone); }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-body);
  font-size: 14px; font-weight: 500; line-height: 1.3;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, border-color 150ms, color 150ms;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.btn-primary:hover  { background: var(--color-primary-pressed); }
.btn-primary:active { background: var(--color-primary-pressed); }
.btn-secondary {
  background: transparent;
  color: var(--color-ink);
  border-color: var(--color-app-border);
}
.btn-secondary:hover { background: var(--color-app-hover); }
.btn-ghost {
  background: transparent;
  color: var(--color-ink);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.btn-ghost:hover { background: var(--color-app-hover); }
.btn-danger {
  background: var(--color-error);
  color: #fff;
}
.btn-link {
  background: transparent;
  color: var(--color-link-blue);
  font-size: 13px;
  padding: 0;
  border: none;
}
.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  color: var(--color-slate);
  cursor: pointer; transition: background 120ms;
}
.btn-icon:hover { background: var(--color-app-hover); color: var(--color-ink); }
.btn-block { width: 100%; }

/* =========================================================
   Panels / cards
   ========================================================= */
.panel {
  background: var(--color-app-panel);
  border: 1px solid var(--color-app-border);
  border-radius: 12px;
}
.panel-pad    { padding: 20px; }
.panel-pad-lg { padding: 28px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-app-border);
}
.panel-head h2, .panel-head h3 {
  font-size: 15px; font-weight: 700; color: var(--color-ink);
}

/* =========================================================
   KPI cards
   ========================================================= */
.kpi {
  background: var(--color-app-panel);
  border: 1px solid var(--color-app-border);
  border-radius: 12px;
  padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.kpi-label { font-size: 13px; color: var(--color-slate); font-weight: 500; }
.kpi-value { font-family: var(--font-heading); font-size: 30px; font-weight: 700; color: var(--color-ink); letter-spacing: -0.5px; }
.kpi-delta { font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up   { color: #16A34A; }
.kpi-delta.down { color: #DC2626; }

/* =========================================================
   Grids
   ========================================================= */
.grid-kpi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-1-1 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* =========================================================
   Status pills + tags
   ========================================================= */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 9999px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.active    { background: var(--color-status-active-bg);    color: var(--color-status-active-fg); }
.pill.pending   { background: var(--color-status-pending-bg);   color: var(--color-status-pending-fg); }
.pill.blocked   { background: var(--color-status-blocked-bg);   color: var(--color-status-blocked-fg); }
.pill.draft     { background: var(--color-status-draft-bg);     color: var(--color-status-draft-fg); }
.pill.published { background: var(--color-status-published-bg); color: var(--color-status-published-fg); }

/* =========================================================
   Data table
   ========================================================= */
.dt-wrap { overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; min-width: 720px; }
.dt thead th {
  font-size: 12px; font-weight: 600; color: var(--color-slate);
  text-align: start;
  padding: 12px 14px;
  background: var(--color-app-bg);
  border-bottom: 1px solid var(--color-app-border);
  white-space: nowrap;
}
.dt tbody td {
  padding: var(--row-pad-y) 14px;
  font-size: 14px;
  color: var(--color-charcoal);
  border-bottom: 1px solid var(--color-app-border-soft);
  vertical-align: middle;
}
.dt tbody tr:hover { background: var(--color-app-hover); }
.dt tbody tr:last-child td { border-bottom: none; }
.dt .row-actions { display: inline-flex; gap: 4px; }

/* =========================================================
   Avatar
   ========================================================= */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 600;
  font-family: var(--font-heading);
  flex-shrink: 0;
  width: 32px; height: 32px; font-size: 13px;
  background: var(--color-primary);
}
.avatar-sm { width: 24px; height: 24px; font-size: 11px; }
.avatar-lg { width: 40px; height: 40px; font-size: 15px; }

/* =========================================================
   Form fields
   ========================================================= */
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld label { font-size: 13px; font-weight: 500; color: var(--color-charcoal); }
.fld .hint  { font-size: 12px; color: var(--color-stone); }
.fld .error { font-size: 12px; color: var(--color-error); }
.fld input, .fld select, .fld textarea {
  font-family: var(--font-body);
  background: var(--color-app-panel);
  color: var(--color-ink);
  border: 1px solid var(--color-app-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
  width: 100%;
}
.fld input:focus, .fld select:focus, .fld textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--color-app-panel);
  border: 1px solid var(--color-app-border);
  border-radius: 8px;
  padding: 0 12px;
  height: 38px;
  color: var(--color-stone);
  min-width: 280px;
}
.search-box input { border: none; outline: none; flex: 1; background: transparent; color: var(--color-ink); font-size: 14px; }

/* =========================================================
   Page header
   ========================================================= */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-header h1 { font-size: 24px; font-weight: 700; }
.filter-row  { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================================================
   Flash / alerts
   ========================================================= */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert .alert-icon { width: 18px; height: 18px; flex-shrink: 0; }
.alert[hidden] { display: none; }
.alert-success { background: var(--color-status-active-bg);  color: var(--color-status-active-fg);  border-color: #BBF7D0; }
.alert-error   { background: var(--color-status-blocked-bg); color: var(--color-status-blocked-fg); border-color: #FECACA; }
.alert-warning { background: var(--color-status-pending-bg); color: var(--color-status-pending-fg); border-color: #FDE68A; }

/* =========================================================
   Icon-prefixed inputs (login fields)
   ========================================================= */
.input-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon-wrap .input-icon-lead {
  position: absolute;
  width: 18px; height: 18px;
  color: var(--color-stone);
  pointer-events: none;
  z-index: 1;
}
[dir="rtl"] .input-icon-wrap .input-icon-lead { right: 12px; }
[dir="ltr"] .input-icon-wrap .input-icon-lead { left:  12px; }

.input-icon-wrap .input-icon-trail {
  position: absolute;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: transparent;
  border: none;
  color: var(--color-stone);
  cursor: pointer;
  border-radius: 6px;
  z-index: 1;
}
.input-icon-wrap .input-icon-trail:hover { color: var(--color-ink); background: var(--color-app-hover); }
.input-icon-wrap .input-icon-trail i { width: 18px; height: 18px; }
[dir="rtl"] .input-icon-wrap .input-icon-trail { left:  6px; }
[dir="ltr"] .input-icon-wrap .input-icon-trail { right: 6px; }

.input-with-icon {
  width: 100%;
  height: 44px;
  font-family: var(--font-body);
  background: var(--color-app-panel);
  color: var(--color-ink);
  border: 1px solid var(--color-app-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
[dir="rtl"] .input-with-icon { padding: 0 40px 0 14px; }
[dir="ltr"] .input-with-icon { padding: 0 14px 0 40px; }
.input-with-icon.has-trail[dir="rtl"],
[dir="rtl"] .input-with-icon.has-trail { padding-left: 44px; }
.input-with-icon.has-trail[dir="ltr"],
[dir="ltr"] .input-with-icon.has-trail { padding-right: 44px; }
.input-with-icon:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.input-with-icon.is-invalid {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(212, 76, 71, 0.18);
}
.input-with-icon::placeholder { color: var(--color-stone); }

/* =========================================================
   Stateful button (loading / success / error)
   ========================================================= */
.btn-stateful {
  position: relative;
  overflow: hidden;
  transition: background 200ms ease-out, color 200ms ease-out;
}
.btn-stateful .btn-content,
.btn-stateful .btn-state {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity 180ms ease-out, transform 220ms ease-out;
}
.btn-stateful .btn-state {
  position: absolute; inset: 0;
  opacity: 0; transform: scale(0.85);
  pointer-events: none;
}
.btn-stateful[data-state="loading"] .btn-content { opacity: 0; transform: scale(0.95); }
.btn-stateful[data-state="loading"] .btn-state   { opacity: 1; transform: scale(1); }
.btn-stateful[data-state="success"] .btn-content { opacity: 0; }
.btn-stateful[data-state="success"] .btn-state   { opacity: 1; transform: scale(1); }
.btn-stateful[data-state="error"]   .btn-content { opacity: 0; }
.btn-stateful[data-state="error"]   .btn-state   { opacity: 1; transform: scale(1); }
.btn-stateful[data-state]:not([data-state=""]) { pointer-events: none; }
.btn-stateful.btn-primary[data-state="success"] { background: var(--color-success); }
.btn-stateful.btn-primary[data-state="error"]   { background: var(--color-error); }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: mc-spin 0.7s linear infinite;
}
@keyframes mc-spin { to { transform: rotate(360deg); } }

/* Animated checkmark drawn via stroke-dashoffset */
.checkmark {
  width: 22px; height: 22px;
  display: inline-block;
}
.checkmark svg { width: 100%; height: 100%; overflow: visible; }
.checkmark circle, .checkmark path {
  fill: none; stroke: currentColor; stroke-width: 2.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.checkmark circle { stroke-dasharray: 76; stroke-dashoffset: 76; animation: mc-draw 0.35s ease-out forwards; }
.checkmark path   { stroke-dasharray: 28; stroke-dashoffset: 28; animation: mc-draw 0.3s 0.25s ease-out forwards; }
@keyframes mc-draw { to { stroke-dashoffset: 0; } }

/* Animated X */
.xmark {
  width: 22px; height: 22px;
  display: inline-block;
}
.xmark svg { width: 100%; height: 100%; overflow: visible; }
.xmark line, .xmark circle {
  fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round;
}
.xmark circle { stroke-dasharray: 76; stroke-dashoffset: 76; animation: mc-draw 0.3s ease-out forwards; }
.xmark line:nth-child(2) { stroke-dasharray: 18; stroke-dashoffset: 18; animation: mc-draw 0.22s 0.22s ease-out forwards; }
.xmark line:nth-child(3) { stroke-dasharray: 18; stroke-dashoffset: 18; animation: mc-draw 0.22s 0.34s ease-out forwards; }

/* Shake on error (applied to the whole login card) */
@keyframes mc-shake {
  0%, 100% { transform: translateX(0); }
  15%, 55% { transform: translateX(-6px); }
  30%, 70% { transform: translateX(6px); }
  85%      { transform: translateX(-3px); }
}
.shake { animation: mc-shake 0.45s ease-in-out; }

/* Fields locked during submit */
.is-locked input, .is-locked button:not(.btn-stateful), .is-locked select { opacity: 0.6; cursor: not-allowed; }

/* =========================================================
   Redirect overlay (full-screen, branded)
   ========================================================= */
.redirect-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, var(--color-primary-deep) 0%, var(--color-primary) 100%);
  color: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  z-index: 10000;
  opacity: 0;
  animation: mc-fade-in 0.25s ease-out forwards;
}
@keyframes mc-fade-in { to { opacity: 1; } }
.redirect-overlay .ro-logo {
  width: 76px; height: 76px;
  background: rgba(255,255,255,0.16);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-weight: 700;
  font-size: 36px; color: #fff;
  animation: mc-pulse 1.4s ease-in-out infinite;
}
@keyframes mc-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.4); }
  50%      { transform: scale(1.06); box-shadow: 0 0 0 18px rgba(255,255,255,0); }
}
.redirect-overlay .ro-title {
  font-family: var(--font-heading); font-weight: 700; font-size: 22px;
  letter-spacing: -0.3px;
}
.redirect-overlay .ro-sub {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; opacity: 0.85;
}
.redirect-overlay .ro-sub .spinner {
  width: 14px; height: 14px; border-width: 2px;
}
.redirect-overlay .ro-progress {
  width: 220px; height: 3px; border-radius: 999px;
  background: rgba(255,255,255,0.2);
  overflow: hidden;
  margin-top: 6px;
}
.redirect-overlay .ro-progress::before {
  content: ""; display: block; height: 100%;
  background: #fff;
  width: 30%;
  border-radius: 999px;
  animation: mc-slide 1.2s ease-in-out infinite;
}
@keyframes mc-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(380%); }
}

/* =========================================================
   Login layout
   ========================================================= */
.login-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  background: var(--color-app-bg);
}
.login-side {
  background: linear-gradient(160deg, var(--color-primary-deep) 0%, var(--color-primary) 100%);
  color: #fff;
  padding: 56px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-side .brand-mark { display: flex; align-items: center; gap: 12px; font-family: var(--font-heading); font-weight: 700; font-size: 20px; }
.login-side .brand-mark .dot { width: 32px; height: 32px; border-radius: 8px; background: rgba(255,255,255,0.18); display: inline-flex; align-items: center; justify-content: center; }
.login-hero {
  font-family: var(--font-heading);
  font-size: 44px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.5px;
  max-width: 480px;
}
.login-sub { opacity: 0.85; max-width: 460px; line-height: 1.65; font-size: 16px; margin-top: 14px; }
.login-side .login-foot { font-size: 13px; opacity: 0.75; }

.login-pane {
  background: var(--color-app-panel);
  padding: 64px;
  display: flex; align-items: center; justify-content: center;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.login-card .lede { color: var(--color-slate); font-size: 14px; margin-bottom: 28px; }
.login-row { display: flex; flex-direction: column; gap: 16px; }
.login-options { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--color-slate); }
.login-options label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* =========================================================
   Empty state
   ========================================================= */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px;
  color: var(--color-stone);
  text-align: center;
  gap: 6px;
}
.empty .title { font-family: var(--font-heading); font-weight: 700; font-size: 16px; color: var(--color-charcoal); }

/* =========================================================
   Utilities
   ========================================================= */
.flex          { display: flex; }
.flex-col      { display: flex; flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }  .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.flex-1 { flex: 1; }
.mt-2 { margin-top: 8px; }  .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-slate { color: var(--color-slate); }
.text-stone { color: var(--color-stone); }
.text-ink   { color: var(--color-ink); }
.text-sm    { font-size: 13px; }
.text-xs    { font-size: 12px; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }

input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1024px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .grid-2-1 { grid-template-columns: 1fr; }
  .login-grid { grid-template-columns: 1fr; }
  .login-side { display: none; }
  .app-content { padding: 20px 18px; }
}
@media (max-width: 640px) {
  .grid-kpi { grid-template-columns: 1fr; gap: 12px; }
  .grid-1-1 { grid-template-columns: 1fr; gap: 12px; }
  .app-content { padding: 16px 14px; }
  .topbar { height: 56px; padding: 0 12px; }
  .topbar .search-box { display: none; }
  .topbar .topbar-user-text { display: none; }
  .login-pane { padding: 24px; }
  .login-hero { font-size: 28px; line-height: 1.2; }
}
