:root {
  --bg: #f5f9f4; --panel: #fff; --ink: #242820; --muted: #5f6b5c; --line: #dfe9dc; --brand: #3d8540; --brand-2: #519e52; --brand-soft: #e8f3e6;
  --ok: #1f7a4d; --warn: #a86a00; --bad: #b3261e; --info: #2f6fa8; --chip: #eef5ec; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.05);
  --radius: 10px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 38px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); } .btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; } .btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; padding: 6px 8px; border-radius: 6px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; width: 100%; max-width: 380px; box-shadow: var(--shadow); display: grid; gap: 14px; border: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; } .brand small { display: block; color: var(--muted); font-size: 12px; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.brand.big .logo { width: 44px; height: 44px; font-size: 20px; }
#app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; flex: none; }
.sidebar nav { display: grid; gap: 2px; } .sidebar nav a { padding: 9px 12px; border-radius: 8px; color: var(--ink); }
.sidebar nav a:hover { background: var(--chip); text-decoration: none; } .sidebar nav a.active { background: var(--brand); color: #fff; }
.me { margin-top: auto; display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding: 0 8px; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
#menuBtn { display: none; }
main { padding: 20px 24px 60px; max-width: 1400px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; } .cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); display: block; }
.stat:hover { text-decoration: none; border-color: var(--brand-2); }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; } .stat .l { color: var(--muted); font-size: 12px; }
.stat.ok .n { color: var(--ok); } .stat.warn .n { color: var(--warn); } .stat.bad .n { color: var(--bad); } .stat.info .n { color: var(--info); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: end; }
.filters > * { flex: 1 1 140px; max-width: 220px; } .filters .grow { flex: 2 1 220px; max-width: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--chip); position: sticky; top: 0; white-space: nowrap; }
th[data-sort] { cursor: pointer; } tr:last-child td { border-bottom: 0; } tbody tr:hover { background: color-mix(in srgb, var(--chip) 60%, transparent); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.Available, .badge.new, .badge.ok { background: #e3f4ea; color: var(--ok); } .badge.Assigned, .badge.update { background: #e4eef9; color: var(--info); }
.badge.Under-Repair, .badge.warn { background: #fdf0d9; color: var(--warn); } .badge.Lost, .badge.Retired, .badge.error, .badge.duplicate, .badge.bad { background: #fbe4e2; color: var(--bad); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); } .form .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; grid-column: 1 / -1; margin-top: 4px; }
.error { color: var(--bad); margin: 0; } .muted { color: var(--muted); } .warnbox { background: #fdf0d9; color: #6e4700; padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.okbox { background: #e3f4ea; color: #155c39; padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.modal { position: fixed; inset: 0; background: rgba(10, 18, 28, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 14px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; padding: 18px 20px; border: 1px solid var(--line); }
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; } .modal-card header h2 { margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1b2430; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.bad { background: var(--bad); }
.timeline { list-style: none; padding: 0; margin: 0; } .timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); position: absolute; left: -6px; top: 15px; }
.timeline li.closed::before { background: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; } .chip { background: var(--chip); border-radius: 999px; padding: 4px 10px; display: inline-flex; gap: 6px; align-items: center; }
.chip.off { opacity: .5; text-decoration: line-through; }
.pick { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; } .pick label { display: flex; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 400; color: var(--ink); cursor: pointer; align-items: center; }
.pick input { width: auto; min-height: 0; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; background: var(--chip); border-radius: 8px; margin-bottom: 10px; }
.bulkbar select { width: auto; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; } .photos img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
input[type=checkbox] { width: auto; min-height: 0; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s; box-shadow: var(--shadow); } .sidebar.open { left: 0; }
  #menuBtn { display: block; } main { padding: 16px; } .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .cols-2, .cols-3, .form { grid-template-columns: 1fr; } .kv { grid-template-columns: 120px 1fr; }
  .filters > * { max-width: none; } .hide-sm { display: none; }
}
@media print { .sidebar, .topbar, .no-print { display: none !important; } main { padding: 0; } .panel { box-shadow: none; } }

/* v2 additions */
.branch-pick { width: auto; max-width: 220px; min-height: 34px; padding: 4px 8px; font-weight: 600; border-color: var(--brand-2); }
.thumb { border-radius: 6px; object-fit: cover; border: 1px solid var(--line); vertical-align: middle; display: inline-block; background: var(--chip); }
.thumb.ph { background: repeating-linear-gradient(45deg, var(--chip), var(--chip) 4px, transparent 4px, transparent 8px); }
.stat .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; } .tabs a { padding: 7px 12px; border-radius: 999px; background: var(--chip); color: var(--ink); }
.tabs a.on { background: var(--brand); color: #fff; } .tabs a:hover { text-decoration: none; }
.tl li { padding-top: 8px; padding-bottom: 8px; } .tl-h { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; } .tl-i { width: 18px; text-align: center; }
.tl-b { margin: 2px 0 0 26px; } .tl li.complaint::before { background: var(--warn); } .tl li.returned::before, .tl li.transferred_out::before { background: var(--muted); }
.tl li.repair::before { background: var(--warn); } .tl li.branch_transfer::before { background: var(--ok); }
.strike { text-decoration: line-through; color: var(--muted); }
.mainphoto { position: relative; margin-bottom: 10px; } .mainphoto img { width: 100%; max-height: 280px; object-fit: contain; background: var(--chip); border-radius: 8px; border: 1px solid var(--line); }
.mainphoto .badge { position: absolute; top: 8px; left: 8px; }
.photos figure { margin: 0; width: 130px; font-size: 12px; } .photos figure img { width: 130px; height: 110px; }
.sens { border: 1px dashed var(--warn); border-radius: 8px; padding: 8px 10px 12px; } .sens legend { font-size: 12px; font-weight: 700; color: var(--warn); }
.modal-card.wide { max-width: 980px; }
.pick .sub { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 6px 10px 10px 34px; border-bottom: 1px solid var(--line); gap: 8px; }
.pick .sub label { border: 0; padding: 0; display: block; }
tr.sel-row td { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.badge.Open, .badge.In-Progress, .badge.Awaiting-Repair { background: #fdf0d9; color: var(--warn); } .badge.Resolved, .badge.Closed, .badge.active { background: #e3f4ea; color: var(--ok); }
.badge.invited { background: #e4eef9; color: var(--info); } .badge.revoked, .badge.Resigned, .badge.Terminated, .badge.Inactive { background: #fbe4e2; color: var(--bad); } .badge.Notice-Period { background: #fdf0d9; color: var(--warn); }
@media (max-width: 900px) { .pick .sub { grid-template-columns: 1fr 1fr; padding-left: 10px; } .branch-pick { order: 3; max-width: none; flex: 1 1 100%; } }

/* Atlas identity: white surfaces, logo green accents */
:root { color-scheme: light; }
.sidebar { border-right: 1px solid var(--line); box-shadow: inset -3px 0 0 var(--brand-soft); }
.sidebar nav a:hover { background: var(--brand-soft); color: var(--brand); }
.sidebar nav a.active { background: var(--brand); color: #fff; box-shadow: inset 3px 0 0 var(--brand-2); }
.topbar { border-bottom: 3px solid var(--brand-2); }
.topbar h1 { color: var(--brand); }
th { background: var(--brand-soft); color: #2f5f31; }
.panel h2, .panel h3 { color: var(--brand); }
.stat { border-top: 3px solid var(--brand-2); }
.stat .n { color: var(--brand); }
.btn:hover { border-color: var(--brand-2); color: var(--brand); }
.btn.primary:hover { color: #fff; }
.login { background: linear-gradient(160deg, #fff 0%, var(--brand-soft) 100%); }
.login-card { border-top: 4px solid var(--brand-2); }
.brand-logo { width: 100%; max-width: 200px; height: auto; display: block; margin-bottom: 4px; }
.sidebar .brand small { padding-left: 2px; color: var(--brand); font-weight: 600; }
.brand.big .brand-logo { max-width: 260px; margin: 0 auto 6px; }
.brand.big { flex-direction: column; text-align: center; }

/* ===== Responsive layer: iPhone 16/17 Pro, Galaxy A36, Honor, Z Fold 6 (cover+inner), Xiaomi Pad 7, MacBook Pro ===== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; overflow-wrap: anywhere; -webkit-tap-highlight-color: transparent; }
body.no-scroll { overflow: hidden; }
img, video, canvas, svg { max-width: 100%; }
.backdrop { display: none; }
.sidebar nav { overflow-y: auto; min-height: 0; }
.sidebar { height: 100vh; height: 100dvh; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.topbar { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); padding-top: max(14px, env(safe-area-inset-top)); }
.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); padding-bottom: max(60px, calc(env(safe-area-inset-bottom) + 40px)); margin: 0 auto 0 0; }
.toast { bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px)); width: max-content; }
.modal-card { max-height: 92vh; max-height: 92dvh; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.table-wrap table { min-width: 560px; }
.kv dd, .kv dt { min-width: 0; }
.photos figure, .photos img { max-width: 100%; }

/* Large desktop (MacBook Pro 14"/16" and up) */
@media (min-width: 1280px) {
  .sidebar { width: 260px; }
  main { padding-left: 32px; padding-right: 32px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
}
@media (min-width: 1700px) { main { max-width: 1600px; } body { font-size: 15px; } }

/* Tablets in landscape / small laptops (Xiaomi Pad 7 landscape, iPad) */
@media (min-width: 901px) and (max-width: 1180px) {
  .sidebar { width: 210px; }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding-left: 18px; padding-right: 18px; }
}

/* Tablet portrait + foldable inner screens (Z Fold 6 unfolded, Xiaomi Pad 7 portrait) */
@media (max-width: 900px) {
  .sidebar { left: -290px; width: min(280px, 85vw); padding-top: max(16px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); box-shadow: none; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .backdrop { display: block; position: fixed; inset: 0; background: rgba(10,18,28,.45); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .backdrop.show { opacity: 1; pointer-events: auto; }
  .sidebar nav a { padding: 12px 14px; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); gap: 8px; }
  main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  #menuBtn { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; font-size: 22px; }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: 1fr; }
  .topbar .actions { flex: 1 1 100%; margin-left: 0; }
  .modal-card.wide { max-width: 100%; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* Phones (iPhone 16/17 Pro ~393px, Galaxy A36 ~412px, Honor ~360-412px) */
@media (max-width: 640px) {
  body { font-size: 15px; }
  /* 16px inputs stop iOS Safari zooming on focus; 44px touch targets */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; flex: none; }
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.small { min-height: 40px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  h1 { font-size: 18px; }
  .cols-3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; } .stat .n { font-size: 22px; }
  .panel { padding: 14px 12px; margin-bottom: 12px; }
  .filters > *, .filters .grow { flex: 1 1 100%; max-width: none; }
  .form-actions { flex-direction: column-reverse; } .form-actions .btn { width: 100%; justify-content: center; }
  .topbar .actions { flex-wrap: wrap; } .topbar .actions .btn { flex: 1 1 auto; justify-content: center; }
  /* inline max-width inputs inside rows become full width */
  .row > input:not([type=checkbox]):not([type=radio]), .row > select, .row > .btn { flex: 1 1 100%; max-width: none !important; }
  .row > label.row, .row > label { max-width: none; }
  .kv { grid-template-columns: 1fr; gap: 0; } .kv dt { margin-top: 10px; font-size: 12px; } .kv dd { margin-bottom: 2px; }
  .pick .sub { grid-template-columns: 1fr; }
  .pick label { padding: 12px 10px; flex-wrap: wrap; }
  .photos figure, .photos figure img { width: calc(50% - 4px); } .photos img { width: calc(50% - 4px); height: 120px; }
  th, td { padding: 8px 10px; }
  .mainphoto img { max-height: 220px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; } .tabs a { white-space: nowrap; flex: none; }
  .bulkbar { gap: 6px; } .bulkbar select { width: 100%; }
  /* modal becomes a bottom sheet */
  .modal { padding: 0; align-items: end; padding-top: env(safe-area-inset-top); }
  .modal-card { border-radius: 16px 16px 0 0; max-height: 94vh; max-height: 94dvh; padding: 16px 14px max(16px, env(safe-area-inset-bottom)); max-width: 100%; }
  .modal-card header { position: sticky; top: -16px; background: var(--panel); z-index: 1; padding: 4px 0; }
  .toast { max-width: calc(100vw - 24px); width: calc(100vw - 24px); text-align: center; }
  .login-card { padding: 22px 18px; }
  .brand.big .brand-logo { max-width: 200px; }
}

/* Very narrow: Z Fold 6 cover screen (~344px) and small Honor/Android phones (<=360px) */
@media (max-width: 360px) {
  main, .topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; } .stat .n { font-size: 20px; } .stat .l { font-size: 11px; }
  .panel { padding: 12px 10px; }
  .btn { padding: 10px 10px; font-size: 14px; }
  .table-wrap table { min-width: 480px; }
  h1 { font-size: 16px; }
  .login { padding: 10px; }
}

/* Landscape phones (short viewport) */
@media (max-height: 480px) and (orientation: landscape) {
  .login { place-items: start center; }
  .modal-card { max-height: 100dvh; border-radius: 0; }
  .topbar { position: static; }
  .sidebar nav a { padding: 8px 12px; }
}

/* Touch devices: no hover-only affordances, comfortable targets */
@media (hover: none) and (pointer: coarse) {
  .btn:hover, .stat:hover { border-color: var(--line); color: inherit; }
  .btn.primary:hover { color: #fff; border-color: var(--brand); }
  .sidebar nav a:hover { background: transparent; }
  .sidebar nav a.active:hover { background: var(--brand); color: #fff; }
  .link { min-height: 32px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
