:root {
  --cream: #f7f0e5;
  --paper: #fffaf2;
  --white: #ffffff;
  --navy: #233f70;
  --red: #c52d2f;
  --dark: #18202b;
  --muted: rgba(24, 32, 43, 0.64);
  --line: rgba(35, 63, 112, 0.13);
  --green: #238442;
  --green-soft: #e8f4e9;
  --red-soft: #fbe8e5;
  --shadow: 0 16px 42px rgba(35, 63, 112, 0.1);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--dark);
  background: var(--cream);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(197, 45, 47, 0.24); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-panel {
  width: min(100%, 430px);
  padding: 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-brand, .admin-brand { display: inline-flex; align-items: center; gap: 11px; color: var(--navy); text-decoration: none; }
.login-brand img, .admin-brand img { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; }
.login-brand span, .admin-brand span { display: grid; line-height: 1; }
.login-brand strong, .admin-brand strong { font-size: 1rem; font-weight: 900; letter-spacing: 0.04em; }
.login-brand small, .admin-brand small { margin-top: 4px; font-size: 0.61rem; font-weight: 800; letter-spacing: 0.2em; }
.login-copy { margin: 44px 0 26px; }
.login-copy p { margin: 0 0 8px; color: var(--red); font-size: 0.73rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.13em; }
.login-copy h1 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 9vw, 2.7rem); line-height: 1.02; }
.login-copy span { display: block; margin-top: 12px; color: var(--muted); line-height: 1.5; }
.login-form label { display: grid; gap: 8px; color: var(--navy); font-size: 0.82rem; font-weight: 850; }
.login-form input { width: 100%; min-height: 52px; padding: 0 15px; color: var(--dark); background: var(--white); border: 1px solid var(--line); border-radius: 8px; }
.login-form button { width: 100%; min-height: 52px; margin-top: 14px; color: var(--white); background: var(--red); border: 0; border-radius: 8px; font-weight: 900; }
.login-form button:disabled { opacity: 0.55; cursor: wait; }
.form-error { margin: 10px 0 0; color: var(--red); font-size: 0.8rem; font-weight: 750; }
.language-link { display: block; margin: 20px auto 0; padding: 8px 12px; color: var(--navy); background: transparent; border: 0; font-weight: 800; }

.admin-app { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  width: 224px;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  background: var(--paper);
  border-inline-end: 1px solid var(--line);
}
[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
.admin-brand { margin: 0 6px 34px; }
.side-nav { display: grid; gap: 7px; }
.side-nav button, .logout-button {
  min-height: 46px;
  padding: 0 14px;
  color: var(--dark);
  background: transparent;
  border: 0;
  border-radius: 7px;
  text-align: start;
  font-weight: 760;
}
.side-nav button.is-active { color: var(--white); background: var(--navy); }
.logout-button { margin-top: auto; color: var(--red); border-top: 1px solid var(--line); border-radius: 0; }
.admin-main { min-height: 100vh; margin-inline-start: 224px; padding: 0 30px 48px; }
.admin-header {
  position: sticky;
  top: 0;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 88px;
  margin: 0 -30px 26px;
  padding: 14px 30px;
  background: rgba(247, 240, 229, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.admin-header p { margin: 0 0 5px; color: var(--red); font-size: 0.7rem; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
.admin-header h1 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 1.8rem; line-height: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.language-button, .refresh-button { min-height: 40px; padding: 0 13px; color: var(--navy); background: var(--white); border: 1px solid var(--line); border-radius: 7px; font-size: 0.78rem; font-weight: 850; }
.refresh-button { color: var(--white); background: var(--navy); }
.global-message { margin: 0 0 20px; padding: 12px 14px; color: var(--red); background: var(--red-soft); border: 1px solid rgba(197,45,47,.18); border-radius: 8px; font-size: 0.82rem; font-weight: 750; }
.metrics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.metric-card, .panel { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(35,63,112,.05); }
.metric-card { min-height: 166px; padding: 22px; }
.metric-card > span { color: var(--muted); font-size: 0.82rem; font-weight: 750; }
.metric-card > strong { display: block; margin: 10px 0 11px; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.2rem, 5vw, 3.4rem); line-height: 1; }
.metric-card small { color: var(--muted); font-size: 0.78rem; }
.trend-up { color: var(--green) !important; }
.trend-down { color: var(--red) !important; }
.panel { padding: 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 1.18rem; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 0.75rem; }
.chart-panel { margin-bottom: 16px; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.chart-legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-inline-end: 5px; border-radius: 50%; }
.chart-legend .up::before { background: var(--green); }
.chart-legend .down::before { background: var(--red); }
.chart { width: 100%; min-height: 280px; overflow: hidden; }
.chart svg { display: block; width: 100%; height: 280px; }
.chart text { fill: var(--muted); font: 11px "Segoe UI", system-ui, sans-serif; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr); gap: 16px; }
.empty-state { display: grid; place-items: center; min-height: 190px; padding: 28px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--navy); }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th, .data-table td { padding: 12px 9px; border-top: 1px solid var(--line); text-align: start; font-size: 0.77rem; vertical-align: middle; overflow-wrap: anywhere; }
.data-table th { color: var(--muted); font-size: 0.68rem; font-weight: 850; text-transform: uppercase; }
.data-table strong { color: var(--navy); }
.status-select { width: 100%; min-height: 36px; padding: 0 28px 0 9px; color: var(--navy); background: var(--white); border: 1px solid var(--line); border-radius: 6px; font-size: 0.72rem; font-weight: 800; }
[dir="rtl"] .status-select { padding: 0 9px 0 28px; }
.rank-list { display: grid; gap: 0; }
.rank-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 13px 0; border-top: 1px solid var(--line); }
.rank-row b { display: grid; place-items: center; width: 26px; height: 26px; color: var(--red); background: var(--red-soft); border-radius: 50%; font-size: 0.72rem; }
.rank-row strong { color: var(--navy); font-size: 0.8rem; }
.rank-row span { color: var(--muted); font-size: 0.72rem; }
.full-panel { min-height: 470px; }
.product-report-panel { margin-top: 16px; }
.mobile-order-list { display: none; }
.order-card { padding: 14px 0; border-top: 1px solid var(--line); }
.order-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.order-card-head strong { color: var(--navy); }
.order-card-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px 12px; margin-bottom: 10px; }
.order-card-grid span { color: var(--muted); font-size: 0.72rem; }
.order-card-grid b { display: block; margin-top: 2px; color: var(--dark); font-size: 0.78rem; }
.stock-groups { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 18px; }
.stock-group h3 { margin: 0 0 8px; color: var(--red); font-size: 0.74rem; letter-spacing: .08em; text-transform: uppercase; }
.stock-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 10px 0; border-top: 1px solid var(--line); }
.stock-row strong { min-width: 0; color: var(--navy); font-size: 0.77rem; }
.stock-row button { flex: 0 0 auto; min-width: 84px; min-height: 34px; padding: 0 10px; color: var(--green); background: var(--green-soft); border: 0; border-radius: 999px; font-size: 0.7rem; font-weight: 900; }
.stock-row button.is-sold-out { color: var(--red); background: var(--red-soft); }
.stock-row button:disabled { opacity: .55; cursor: wait; }
.mobile-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { width: 190px; }
  .admin-main { margin-inline-start: 190px; padding-inline: 20px; }
  .admin-header { margin-inline: -20px; padding-inline: 20px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .stock-groups { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .admin-main { margin: 0; padding: 0 14px 30px; }
  .admin-header { min-height: 78px; margin: 0 -14px 16px; padding: 12px 14px; }
  .admin-header p { display: none; }
  .admin-header h1 { font-size: 1.45rem; }
  .refresh-button { width: 42px; padding: 0; overflow: hidden; font-size: 0; }
  .refresh-button::after { content: "↻"; font-size: 1.2rem; }
  .metrics-grid { gap: 10px; }
  .metric-card { min-height: 132px; padding: 16px; }
  .metric-card > strong { font-size: clamp(1.85rem, 9vw, 2.45rem); }
  .metric-card small { font-size: .68rem; }
  .panel { padding: 15px; border-radius: 9px; }
  .panel-heading { margin-bottom: 12px; }
  .chart-legend { gap: 8px; font-size: .64rem; }
  .chart { min-height: 230px; margin-inline: -5px; width: calc(100% + 10px); }
  .chart svg { height: 230px; }
  .desktop-orders { display: none; }
  .mobile-order-list { display: block; }
  .stock-groups { grid-template-columns: 1fr; }
  .mobile-nav {
    position: fixed;
    inset: auto 10px calc(8px + env(safe-area-inset-bottom)) 10px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3,1fr);
    padding: 6px;
    background: rgba(255,250,242,.96);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(35,63,112,.18);
    backdrop-filter: blur(16px);
  }
  .mobile-nav button { min-height: 46px; padding: 0 5px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: .7rem; font-weight: 850; }
  .mobile-nav button.is-active { color: var(--white); background: var(--navy); }
}

@media (max-width: 390px) {
  .login-panel { padding: 22px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 118px; }
  .metric-card > strong { font-size: 2.25rem; }
  .chart-legend { display: none; }
}

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