:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --purple: #7c3aed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Heebo", "Noto Sans Hebrew", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
a { touch-action: manipulation; }
/* 16px inputs prevent iOS auto-zoom on focus */
input, select, textarea { font-family: inherit; font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- layout ---------- */
.topbar {
  background: #0f172a;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.topbar nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.topbar nav a.active { background: var(--primary); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar select {
  background: #1e293b; color: #fff; border: 1px solid #334155;
  border-radius: 8px; padding: 5px 8px;
}
.topbar .user { font-size: 13px; color: #94a3b8; white-space: nowrap; }
.topbar .linkbtn {
  background: none; border: none; color: #cbd5e1; font-size: 13px;
  padding: 6px 8px; border-radius: 8px;
}
.topbar .linkbtn:hover { background: rgba(255,255,255,.1); color: #fff; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 18px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  padding: 20px;
}
.login-box {
  background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-box .logo { font-size: 40px; text-align: center; margin-bottom: 8px; }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-box .lang-row { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }
.login-box .lang-row button {
  background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 12px; font-size: 13px;
}
.login-box .lang-row button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--text);
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e2e8f0; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: var(--green); }
.btn.success:hover { background: #15803d; }
.btn.whatsapp { background: #25d366; }
.btn.whatsapp:hover { background: #1eb855; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 12px; font-size: 13px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.proto { background: #ede9fe; color: var(--purple); }
.badge.prod { background: #dbeafe; color: var(--primary-dark); }
.badge.good { background: #dcfce7; color: var(--green); }
.badge.warn { background: #fef3c7; color: var(--amber); }
.badge.bad { background: #fee2e2; color: var(--red); }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.prio-high { background: #ffedd5; color: #c2410c; }
.badge.prio-urgent { background: #fee2e2; color: var(--red); }

/* ---------- dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; transition: transform .1s;
}
.stat:hover { transform: translateY(-2px); }
.stat .num { font-size: 26px; font-weight: 800; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.accent .num { color: var(--primary); }

.feed-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.feed-item:last-child { border-bottom: none; }
.feed-item .ico { font-size: 16px; }
.feed-item .when { color: var(--muted); font-size: 12px; }

/* ---------- orders table ---------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input[type=text] {
  flex: 1; min-width: 220px; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
}
.filter-bar select { padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table.orders { width: 100%; border-collapse: collapse; }
table.orders th {
  text-align: start; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--border); background: #f8fafc;
}
table.orders td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.orders tr:last-child td { border-bottom: none; }
table.orders tbody tr { cursor: pointer; }
table.orders tbody tr:hover { background: #f8fafc; }
.thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #e2e8f0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.order-num { font-weight: 700; color: var(--primary); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- order detail ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head h2 { font-size: 22px; }
.detail-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { font-weight: 500; overflow-wrap: anywhere; }

.specs { white-space: pre-wrap; font-size: 14px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }

/* timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-stage-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 6px; }
.tl-step { display: flex; gap: 10px; align-items: flex-start; position: relative; padding-bottom: 14px; }
.tl-step .dot {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: #e2e8f0; color: #94a3b8; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; z-index: 1;
}
.tl-step .line {
  position: absolute; top: 22px; inset-inline-start: 10px; width: 2px; bottom: 0; background: #e2e8f0;
}
.tl-step:last-child .line { display: none; }
.tl-step.done .dot { background: var(--green); color: #fff; }
.tl-step.done .line { background: var(--green); }
.tl-step.current .dot { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(37,99,235,.2); }
.tl-step .lbl { font-size: 13.5px; padding-top: 1px; }
.tl-step.current .lbl { font-weight: 700; color: var(--primary-dark); }
.tl-step.done .lbl { color: var(--text); }
.tl-step.todo .lbl { color: var(--muted); }
.tl-step .sub { font-size: 12px; color: var(--muted); }

/* files */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.file-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #f8fafc; text-decoration: none; color: var(--text); }
.file-card img { width: 100%; height: 90px; object-fit: cover; display: block; }
.file-card .pdf { height: 90px; display: flex; align-items: center; justify-content: center; font-size: 32px; }
.file-card .cap { font-size: 11px; padding: 5px 7px; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; }
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* actions */
.action-block { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #f8fafc; }
.action-block .btn { margin-top: 8px; }
.inline-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-inputs input { flex: 1; min-width: 130px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; }

/* size curve editor + table */
.sizes-rows { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.size-row { display: flex; gap: 4px; }
.size-row input[data-sz] { width: 64px; padding: 7px 8px; border: 1px solid #cbd5e1; border-radius: 8px; text-align: center; }
.size-row input[data-qty] { width: 74px; padding: 7px 8px; border: 1px solid #cbd5e1; border-radius: 8px; }
table.sizes-table { border-collapse: collapse; margin-top: 6px; }
table.sizes-table th, table.sizes-table td {
  border: 1px solid var(--border); padding: 5px 12px; text-align: center; font-size: 13.5px;
}
table.sizes-table th { background: #f8fafc; color: var(--muted); font-size: 12px; }

/* activity */
.evt { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.evt:last-child { border-bottom: none; }
.evt .ico { font-size: 16px; flex-shrink: 0; }
.evt .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.evt .msg { white-space: pre-wrap; }
.comment-row { display: flex; gap: 8px; margin-top: 12px; }
.comment-row input { flex: 1; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; }

/* users */
table.users { width: 100%; border-collapse: collapse; }
table.users th, table.users td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.users th { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* contacts directory */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button {
  flex: 1; max-width: 200px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); font-size: 14px; font-weight: 600;
  color: var(--muted); min-height: 44px;
}
.tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.contact-list { display: flex; flex-direction: column; gap: 10px; }
.contact-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer;
}
.contact-card:hover { background: #f8fafc; }
.contact-card:active { background: #f1f5f9; }
.cc-name { font-weight: 700; font-size: 15px; }
.cc-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-order {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 4px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14px;
}
.mini-order:last-child { border-bottom: none; }
.mini-order:hover { background: #f8fafc; }
.mini-order-side { display: flex; align-items: center; gap: 8px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.3);
  max-width: 90vw;
}
[dir="rtl"] .toast { transform: translateX(50%); }
.toast.hidden { display: none; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- bottom navigation (mobile app style) ---------- */
.bottom-nav { display: none; }
.table-scroll { overflow-x: auto; }
.order-cards { display: none; }

/* ---------- mobile layer ---------- */
@media (max-width: 768px) {
  /* top bar: brand + language + account only; nav moves to bottom bar */
  .topbar {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
  }
  .topbar nav { display: none; }
  .topbar .brand { font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
  .topbar .user { display: none; }
  .topbar .linkbtn { min-height: 44px; display: inline-flex; align-items: center; }
  .topbar select { min-height: 38px; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 60;
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 52px;
    text-decoration: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
  }
  .bottom-nav a svg { width: 24px; height: 24px; }
  .bottom-nav a.active { color: var(--primary); background: #eff6ff; }
  .bottom-nav a:active { background: #f1f5f9; }

  .container { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 19px; margin-bottom: 14px; }
  .card { padding: 14px; border-radius: 14px; }

  /* touch targets */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
  .field input, .field select, .field textarea { min-height: 46px; padding: 10px 12px; }
  .field textarea { min-height: 90px; }
  .field { margin-bottom: 16px; }

  /* dashboard */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { min-height: 64px; padding: 12px 14px; }
  .stat .num { font-size: 22px; }

  /* orders: cards instead of table */
  .table-wrap { display: none; }
  .order-cards { display: flex; flex-direction: column; gap: 10px; }
  .order-card {
    display: flex;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
  }
  .order-card:active { background: #f8fafc; }
  .order-card .thumb { width: 56px; height: 56px; flex-shrink: 0; font-size: 22px; }
  .oc-main { flex: 1; min-width: 0; }
  .oc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
  .oc-model { font-weight: 600; margin-top: 2px; }
  .oc-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; }

  /* filters */
  .filter-bar { gap: 8px; }
  .filter-bar input[type=text] { width: 100%; flex: none; min-height: 46px; }
  .filter-bar select { flex: 1; min-width: 0; min-height: 46px; }
  .filter-bar .btn { flex: 1; }

  /* order detail: actions first, full-width buttons */
  .detail-grid { display: flex; flex-direction: column; gap: 14px; }
  .col-side { order: -1; }
  .detail-head { gap: 8px; }
  .detail-head h2 { font-size: 19px; }
  .action-block .btn, .action-block + .btn, .col-side .btn { width: 100%; }
  .inline-inputs input { min-height: 46px; }
  .kv { grid-template-columns: minmax(90px, auto) 1fr; }

  /* size curve editor */
  .size-row input[data-sz] { width: 58px; min-height: 44px; }
  .size-row input[data-qty] { width: 70px; min-height: 44px; }

  /* files */
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .upload-row { flex-direction: column; align-items: stretch; }
  .upload-row input[type=file] { width: 100%; }
  .upload-row select { min-height: 44px; }

  /* comments */
  .comment-row input { min-height: 46px; }

  /* users */
  table.users th, table.users td { white-space: nowrap; }

  /* toast above the bottom nav */
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100vw - 32px); }

  /* login */
  .login-box { padding: 28px 22px; }
  .login-box .lang-row button { min-height: 40px; padding: 6px 14px; }
}
