/* ===================================================================
   Workshop Admin — main application stylesheet (screen only).
   Print output uses the dedicated print-*.css files instead.
=================================================================== */

:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e5e9;
  --color-text: #1f2933;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --sidebar-width: 240px;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--color-bg); color: var(--color-text); font-size: 14px; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: #111827;
  color: #d1d5db;
  flex-shrink: 0;
  padding: 16px 0;
}
.sidebar .brand { padding: 0 20px 16px; font-weight: 700; font-size: 18px; color: #fff; border-bottom: 1px solid #1f2937; margin-bottom: 8px; }
.sidebar .nav-group-label { padding: 12px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; }
.sidebar a { display: block; padding: 8px 20px; color: #d1d5db; }
.sidebar a:hover { background: #1f2937; text-decoration: none; }
.sidebar a.active { background: var(--color-primary); color: #fff; }
.sidebar-upgrade-link { margin-top: 16px; padding: 0 20px; }
.sidebar-upgrade-link a {
  display: block; padding: 8px 12px; border-radius: 6px;
  background: rgba(37, 99, 235, .18); color: #93c5fd;
  font-size: 13px; font-weight: 600; text-align: center;
}
.sidebar-upgrade-link a:hover { background: rgba(37, 99, 235, .3); text-decoration: none; }

.main { flex: 1; min-width: 0; }

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .user-info { display: flex; align-items: center; gap: 10px; }
.topbar .user-info .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--color-primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.topbar .user-info .name { font-weight: 600; }
.topbar .user-info .role { font-size: 12px; color: var(--color-text-muted); }

.content { padding: 24px; }

/* ---------- generic components ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2, .card h3 { margin-top: 0; }

/* ---------- dashboard stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--stat-accent, var(--color-primary));
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card__icon {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: var(--stat-accent-bg, #eff6ff);
}
.stat-card__body { min-width: 0; }
.stat-card__value { font-size: 24px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-card__label { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }

.stat-card--blue   { --stat-accent: #2563eb; --stat-accent-bg: #eff6ff; }
.stat-card--purple { --stat-accent: #7c3aed; --stat-accent-bg: #f5f3ff; }
.stat-card--teal   { --stat-accent: #0d9488; --stat-accent-bg: #f0fdfa; }
.stat-card--indigo { --stat-accent: #4f46e5; --stat-accent-bg: #eef2ff; }
.stat-card--green  { --stat-accent: #16a34a; --stat-accent-bg: #f0fdf4; }
.stat-card--amber  { --stat-accent: #d97706; --stat-accent-bg: #fffbeb; }
.stat-card--red    { --stat-accent: #dc2626; --stat-accent-bg: #fef2f2; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-header h1 { margin: 0; font-size: 22px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--color-text-muted); }
tr:hover td { background: #fafbfc; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
.badge-warning { background: #fef3c7; color: #92400e; }
.mono { font-family: 'Courier New', Courier, monospace; }

.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid transparent; font-size: 14px; cursor: pointer; font-weight: 600; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

form label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13px; }
form input[type=text], form input[type=password], form input[type=email], form input[type=tel],
form input[type=number], form select, form textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 14px;
}
form .form-row { display: flex; gap: 16px; }
form .form-row > * { flex: 1; }
form .hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }
form .checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
form .checkbox-row input { width: auto; }

.alert { padding: 12px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-info { background: #dbeafe; color: #1e40af; }

.perm-matrix { width: 100%; border-collapse: collapse; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }
.perm-matrix .group-row td { background: #f3f4f6; font-weight: 700; text-align: left; }

/* ---------- auth pages ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 32px; width: 340px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-subtitle { color: var(--color-text-muted); margin: 0 0 16px; font-size: 13px; }
.auth-card-wide { width: 420px; }
.auth-footer-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--color-text-muted); }
.trial-badge {
  display: inline-block; background: #dbeafe; color: #1e40af;
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; margin-bottom: 10px;
}

.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 32px; max-width: 420px; text-align: center; }

/* ---------- invoice screen preview + action bar ---------- */
.invoice-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.invoice-preview-frame { width: 100%; height: 80vh; border: 1px solid var(--color-border); border-radius: var(--radius); background: #fff; }

/* ---------- language switcher (topbar + login page) ---------- */
.lang-switcher { display: inline-flex; }
.lang-switcher select {
  padding: 6px 8px; border: 1px solid var(--color-border); border-radius: 6px;
  font-size: 13px; background: var(--color-surface); color: var(--color-text); cursor: pointer;
}
.lang-switcher-auth { position: absolute; top: 16px; inset-inline-end: 16px; }
.auth-card { position: relative; }

/* Codes that should stay left-to-right even inside an RTL page (invoice
   numbers, SKUs, phone numbers, amounts) */
.mono { direction: ltr; unicode-bidi: isolate; }

/* ---------- mobile menu toggle (topbar hamburger) ----------
   Hidden by default (desktop); shown only under the 768px breakpoint
   below, where the sidebar becomes an off-canvas overlay instead of a
   permanent column. */
.topbar-left { display: flex; align-items: center; gap: 12px; }
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px; height: 36px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  cursor: pointer;
  flex-shrink: 0;
}
.mobile-menu-toggle span { display: block; width: 18px; height: 2px; background: var(--color-text); margin: 0 auto; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 900;
}
.sidebar-backdrop.visible { display: block; }

/* ---------- responsive layout (phones & small tablets) ---------- */
@media (max-width: 768px) {
  .mobile-menu-toggle { display: flex; }

  /* Sidebar becomes a slide-in overlay instead of a permanent column. */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 950;
    transform: translateX(-100%);
    transition: transform .2s ease;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0,0,0,.25);
  }
  .sidebar.sidebar-open { transform: translateX(0); }
  [dir="rtl"] .sidebar { left: auto; right: 0; transform: translateX(100%); }
  [dir="rtl"] .sidebar.sidebar-open { transform: translateX(0); }

  .topbar { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .topbar .user-info { gap: 8px; }
  .topbar .user-info .name, .topbar .user-info .role { display: none; }
  .lang-switcher select { padding: 5px 6px; font-size: 12px; }

  .content { padding: 14px; }

  /* Tables commonly overflow a phone's width — let the card that holds
     one scroll horizontally instead of breaking the page layout. */
  .card { overflow-x: auto; }

  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card__icon { width: 38px; height: 38px; font-size: 17px; }
  .stat-card__value { font-size: 20px; }

  form .form-row { flex-direction: column; gap: 0; }

  .auth-card, .auth-card-wide { width: 100%; max-width: 360px; padding: 24px 20px; }
  .lang-switcher-auth { position: static; display: flex; justify-content: flex-end; margin-bottom: 8px; }

  .invoice-actions { gap: 6px; }
  .invoice-actions .btn { flex: 1 1 auto; text-align: center; }
}

/* ---------- RTL layout (Arabic / Farsi / Urdu) ----------
   Flex rows (.app-shell, .topbar, .btn-group, .form-row, ...) already
   mirror correctly under dir="rtl" — flex-direction: row follows the
   writing-mode's inline axis by spec, no override needed. Only actual
   text alignment needs flipping explicitly. */
[dir="rtl"] table th,
[dir="rtl"] table td { text-align: right; }
[dir="rtl"] .perm-matrix td:first-child,
[dir="rtl"] .perm-matrix th:first-child { text-align: right; }
