:root {
  --font: "Inter", "Cairo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f9f7f2;
  --ink: #16211d;
  --muted: #68746f;
  --line: #ddd6c8;
  --accent: #0f766e;
  --accent-2: #b98235;
  --accent-soft: #e4f2ee;
  --danger: #b42318;
  --success: #087443;
  --sidebar: #13211d;
  --sidebar-soft: rgba(255, 255, 255, 0.08);
  --shadow: 0 18px 50px rgba(22, 33, 29, 0.11);
}

[dir="rtl"] {
  --font: "Cairo", "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #101514;
  --surface: #171d1b;
  --surface-2: #202724;
  --ink: #edf1ed;
  --muted: #a4aea8;
  --line: #303a36;
  --accent: #30b6a5;
  --accent-2: #d6a15a;
  --accent-soft: rgba(48, 182, 165, 0.12);
  --danger: #ff8a7c;
  --success: #68d79b;
  --sidebar: #0b1110;
  --sidebar-soft: rgba(255, 255, 255, 0.07);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button { letter-spacing: 0; }

.app-body {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar);
  color: #ffffff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand-mark,
.brand-lock {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #0c4f48);
  color: #ffffff;
  font-weight: 800;
}

.brand strong { display: block; font-size: 1.02rem; }
.brand small { display: block; color: #b6c5bd; margin-top: 2px; }

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

.nav-tabs button,
.ghost-btn,
.control-btn,
.copy-btn,
.table-action {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 12px;
  cursor: pointer;
}

.nav-tabs button {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #dce6e1;
  background: transparent;
  text-align: start;
}

.nav-tabs button.active,
.nav-tabs button:hover {
  color: #ffffff;
  background: var(--sidebar-soft);
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
}

.sidebar-card {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--sidebar-soft);
}

.sidebar-card span,
.sidebar-card small {
  color: #b6c5bd;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: clamp(18px, 2.4vw, 32px);
}

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

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.control-btn,
.account-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.control-btn {
  font-weight: 800;
}

.account-chip {
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: 0; }
h1 { font-size: clamp(1.7rem, 3vw, 2.45rem); }
h2 { font-size: 1.24rem; }

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 22px; }

.hero-strip {
  min-height: 190px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 24px;
  align-items: center;
  padding: 28px;
  border-radius: 8px;
  color: #ffffff;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.94), rgba(22, 33, 29, 0.88)),
    url("https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=1600&q=80");
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
}

.hero-strip .eyebrow { color: #f5c77b; }
.hero-strip h2 { max-width: 760px; font-size: clamp(1.45rem, 3vw, 2.45rem); }

.hero-stat {
  min-height: 126px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
}

.hero-stat span { color: #d8e5df; font-weight: 700; }
.hero-stat strong { display: block; font-size: 2.8rem; }

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

.metrics-grid.compact {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  margin-bottom: 20px;
}

.metric,
.surface,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
  display: grid;
  gap: 8px;
}

.metric span { color: var(--muted); font-weight: 700; }
.metric strong { font-size: 2rem; color: var(--accent); }

.surface {
  padding: clamp(18px, 2vw, 24px);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: end;
}

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

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

.stack-form {
  display: grid;
  gap: 14px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface-2);
  outline: none;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.full { grid-column: 1 / -1; }

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.primary-btn {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn:hover { filter: brightness(0.94); }

.form-message {
  margin: 0;
  color: var(--danger);
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
  table-layout: fixed;
}

th,
td {
  padding: 14px 14px;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
  line-height: 1.35;
}

th {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

td { color: var(--ink); }

.short-url {
  direction: ltr;
  text-align: left;
  color: var(--accent);
  font-weight: 800;
  overflow-wrap: normal;
  word-break: normal;
  white-space: normal;
}

.muted { color: var(--muted); }

.copy-btn,
.table-action {
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.table-action {
  min-height: 34px;
  padding: 0 10px;
}

.table-action.danger {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.link-variants {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.variant-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 30px;
  max-width: 210px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
  direction: ltr;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.82rem;
}

.status-pill.disabled,
.status-pill.archived,
.status-pill.deleted {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.status-pill.paused {
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  color: var(--accent-2);
}

.analysis-panel.hidden {
  display: none;
}

.analysis-panel .analytics-grid {
  margin-top: 18px;
}

.links-list {
  display: grid;
  gap: 14px;
}

.link-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.link-card-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
}

.link-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.link-title-row h3 {
  font-size: 1.08rem;
}

.link-card p {
  margin: 6px 0 0;
  line-height: 1.45;
}

.link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: 360px;
}

.link-card-stats {
  display: grid;
  grid-template-columns: minmax(210px, 1.2fr) repeat(2, minmax(90px, 0.4fr));
  gap: 10px;
}

.link-card-stats span {
  display: grid;
  gap: 4px;
  min-height: 66px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.84rem;
  font-weight: 800;
}

.link-card-stats strong {
  color: var(--ink);
  font-size: 1.12rem;
}

.link-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.link-url-row .short-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  min-height: 110px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.bar-list {
  display: grid;
  gap: 13px;
  margin-top: 18px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 700;
  gap: 14px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(19, 33, 29, 0.82), rgba(15, 118, 110, 0.66)),
    url("https://images.unsplash.com/photo-1600607687939-ce8a6c25118c?auto=format&fit=crop&w=1600&q=80");
  background-size: cover;
  background-position: center;
}

.login-shell {
  width: min(460px, 100%);
}

.login-panel {
  padding: 28px;
  display: grid;
  gap: 18px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
}

.login-tools {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.stack {
  display: grid;
  gap: 16px;
}

@media (max-width: 1120px) {
  .metrics-grid,
  .analytics-grid,
  .admin-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
    gap: 16px;
  }

  .brand {
    min-height: 48px;
  }

  .brand-mark,
  .brand-lock {
    width: 44px;
    height: 44px;
  }

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

  .nav-tabs button {
    min-height: 46px;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .hero-strip {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .metrics-grid,
  .analytics-grid,
  .admin-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .surface,
  .hero-strip {
    padding: 16px;
  }

  .sidebar-card {
    margin-top: 0;
  }

  .link-card-main,
  .link-url-row {
    grid-template-columns: 1fr;
  }

  .link-actions {
    justify-content: flex-start;
    max-width: none;
  }

  .link-card-stats {
    grid-template-columns: 1fr;
  }

  .copy-btn,
  .table-action,
  .primary-btn,
  .control-btn {
    min-height: 44px;
  }

  .link-url-row .short-url {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  table {
    min-width: 760px;
  }
}
