:root {
  --bg: #edf0ed;
  --panel: #ffffff;
  --panel-soft: #f7f8f6;
  --text: #17201d;
  --muted: #68736e;
  --border: #d9dfda;
  --brand: #2f5146;
  --brand-dark: #1a2f2a;
  --brand-deep: #10231f;
  --accent: #b58b46;
  --accent-soft: #f3ead9;
  --ok: #2f6f4e;
  --ok-bg: #e6f2eb;
  --soon: #9a651b;
  --soon-bg: #f8edd9;
  --overdue: #a83a32;
  --overdue-bg: #f7e5e3;
  --shadow: 0 12px 30px rgba(18, 38, 32, .08);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
  background: radial-gradient(circle at top right, #f7f8f5 0, var(--bg) 42%, #e9ede9 100%);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
#app { display: flex; min-height: 100vh; }

/* Login */
.login-screen {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(16,35,31,.96), rgba(37,71,61,.92)),
    repeating-linear-gradient(45deg, transparent 0 22px, rgba(255,255,255,.025) 22px 23px);
}
.login-box {
  background: rgba(255,255,255,.98); padding: 34px 32px 28px; border-radius: 20px; width: 390px;
  box-shadow: 0 24px 70px rgba(0,0,0,.28); text-align: right; border: 1px solid rgba(255,255,255,.4);
}
.brand-mark, .side-mark {
  display: grid; place-items: center; background: var(--brand-dark); color: #fff; font-weight: 800;
  border: 1px solid rgba(181,139,70,.65); letter-spacing: .04em;
}
.brand-mark { width: 54px; height: 54px; border-radius: 14px; margin-bottom: 18px; font-size: 18px; }
.login-box h1 { font-size: 27px; margin: 2px 0 5px; letter-spacing: -.02em; }
.login-box p.subtitle { color: var(--muted); margin: 0 0 22px; font-size: 13.5px; line-height: 1.55; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.field-label { display: block; font-size: 12px; font-weight: 700; color: #45514c; margin: 12px 2px 6px; }
.login-box input { width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfb; outline: none; }
.login-box input:focus { border-color: #77998d; box-shadow: 0 0 0 3px rgba(47,81,70,.09); background: #fff; }
.login-box button { width: 100%; padding: 12px; margin-top: 16px; background: var(--brand); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 750; }
.login-box button:hover { background: var(--brand-dark); }
.login-box .install-btn { margin-top: 9px; background: #fff; color: var(--brand-dark); border: 1px solid #afbbb5; }
.login-box .install-btn:hover { background: #f3f6f4; }
.login-foot { text-align: center; color: #87918c; font-size: 11px; margin-top: 16px; }
.error-text { color: var(--overdue); background: var(--overdue-bg); border-radius: 8px; font-size: 12.5px; margin: 10px 0 4px; min-height: 0; }
.error-text:not(:empty) { padding: 9px 10px; }

/* Sidebar */
.sidebar {
  width: 242px; background: linear-gradient(180deg, var(--brand-deep), #18342d 68%, #1e3a32); color: #fff; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  box-shadow: -8px 0 28px rgba(16,35,31,.08);
}
.side-brand { display: flex; gap: 11px; align-items: center; padding: 2px 7px 17px; border-bottom: 1px solid rgba(255,255,255,.1); }
.side-mark { width: 42px; height: 42px; border-radius: 11px; flex: 0 0 auto; }
.side-brand strong { display: block; font-size: 15px; }
.side-brand span { display: block; color: rgba(255,255,255,.54); font-size: 10.5px; margin-top: 2px; }
.side-section { color: rgba(255,255,255,.4); font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 18px 9px 7px; }
.sidebar nav { flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 11px; margin: 3px 0; color: rgba(255,255,255,.76); font-size: 13.5px;
  border-radius: 9px; transition: .15s ease;
}
.nav-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: rgba(255,255,255,.06); color: #d8c096; font-size: 13px; }
.sidebar nav a.active { background: rgba(255,255,255,.11); color: #fff; box-shadow: inset -3px 0 0 var(--accent); }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .install-area { padding: 7px 3px; }
.sidebar .install-area button { width: 100%; padding: 8px; background: rgba(181,139,70,.12); border: 1px solid rgba(181,139,70,.35); color: #f0ddbb; border-radius: 8px; cursor: pointer; font-size: 12px; }
.sidebar .logout { padding: 12px 5px 0; border-top: 1px solid rgba(255,255,255,.09); }
.user-chip { display: flex; align-items: center; gap: 7px; color: rgba(255,255,255,.75); font-size: 11px; margin-bottom: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #67b588; box-shadow: 0 0 0 3px rgba(103,181,136,.12); display: inline-block; flex: 0 0 auto; }
.sidebar .logout button { width: 100%; padding: 8px; background: transparent; border: 1px solid rgba(255,255,255,.18); color: rgba(255,255,255,.76); border-radius: 7px; cursor: pointer; font-size: 12px; }

/* Main */
.main { flex: 1; padding: 30px 34px 50px; max-width: 1440px; min-width: 0; }
.main h1 { font-size: 25px; margin: 2px 0 0; letter-spacing: -.02em; }
.main h2 { font-size: 16px; margin: 0; }
.page-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.page-head p { margin: 7px 0 0; color: var(--muted); font-size: 12.5px; }
.live-pill { display: inline-flex; align-items: center; gap: 7px; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 8px 11px; font-size: 11.5px; color: #4a5751; box-shadow: 0 4px 14px rgba(0,0,0,.035); }
.live-pill span { width: 7px; height: 7px; border-radius: 50%; background: #4e9b70; box-shadow: 0 0 0 3px #e4f0e8; }
.toolbar { display: flex; gap: 9px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: #fff; outline: none; }
.toolbar input:focus, .toolbar select:focus { border-color: #8ca99f; box-shadow: 0 0 0 3px rgba(47,81,70,.07); }
.tactical-toolbar { background: #fff; border: 1px solid var(--border); padding: 10px; border-radius: 12px; box-shadow: 0 5px 16px rgba(20,45,37,.035); }
.search-wide { min-width: 300px; flex: 1; }
.active-filter { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-size: 12px; font-weight: 700; }
.btn { padding: 8px 13px; border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; font-weight: 650; }
.btn:hover { background: #f4f6f4; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 5px 13px rgba(47,81,70,.16); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.small { padding: 5px 9px; font-size: 12px; }

/* Status dashboard */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px,1fr)); gap: 12px; margin-bottom: 18px; }
.tactical-stats { grid-template-columns: repeat(3, minmax(170px,1fr)); }
.stat-tile { display: block; background: var(--panel); border-radius: 13px; border: 1px solid var(--border); padding: 15px 16px; color: var(--text); position: relative; overflow: hidden; box-shadow: 0 4px 15px rgba(20,45,37,.035); }
.stat-tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: #b6c0bb; }
.stat-tile .stat-kicker { color: #8a948f; font-size: 10px; font-weight: 800; letter-spacing: .06em; margin-bottom: 6px; }
.stat-tile .num { font-size: 28px; line-height: 1; font-weight: 800; }
.stat-tile .label { color: var(--muted); font-size: 11.5px; margin-top: 6px; }
.stat-tile.overdue::before { background: var(--overdue); }
.stat-tile.overdue .num { color: var(--overdue); }
.stat-tile.soon::before { background: var(--soon); }
.stat-tile.soon .num { color: var(--soon); }
.stat-tile.ok::before { background: var(--ok); }
.stat-tile.ok .num { color: var(--ok); }
.command-strip { display: flex; align-items: center; justify-content: space-between; gap: 15px; background: var(--brand-dark); color: #fff; border-radius: 12px; padding: 13px 15px; margin-bottom: 18px; box-shadow: var(--shadow); }
.command-strip > div:first-child { display: flex; align-items: baseline; gap: 12px; }
.command-strip span:first-child { color: rgba(255,255,255,.68); font-size: 11px; }
.command-strip strong { font-size: 14px; }

/* Cards / tables */
.card { background: var(--panel); border-radius: var(--radius); border: 1px solid var(--border); padding: 17px; margin-bottom: 14px; box-shadow: 0 5px 18px rgba(20,45,37,.035); }
.section-card { padding-top: 13px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title > div { display: flex; align-items: center; gap: 9px; }
.section-code { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--panel-soft); border: 1px solid var(--border); color: var(--accent); font-size: 10px; font-weight: 800; }
.list-summary { color: var(--muted); font-size: 12px; margin: 4px 2px 8px; }
.list-summary strong { color: var(--text); }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); overflow: hidden; }
table th, table td { padding: 10px 11px; text-align: right; border-bottom: 1px solid #e7ebe8; font-size: 13px; vertical-align: middle; }
table th { background: #f3f5f3; color: #69736f; font-weight: 700; font-size: 11.5px; }
table thead th:first-child { border-radius: 0 9px 0 0; }
table thead th:last-child { border-radius: 9px 0 0 0; }
table tbody tr:last-child td { border-bottom: 0; }
table tr:hover td { background: #f8faf8; }
table.clickable tr { cursor: pointer; }
.person-cell { display: flex; align-items: center; gap: 8px; }
.person-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.row-arrow { text-align: left; color: #9aa39f; font-size: 20px; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.badge.overdue, .badge.expired, .badge.missing { background: var(--overdue-bg); color: var(--overdue); }
.badge.soon, .badge.pending_signature { background: var(--soon-bg); color: var(--soon); }
.badge.ok, .badge.signed, .badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.candidate { background: #e9edf2; color: #576575; }
.badge.inactive { background: #efefef; color: #777; }

/* Person / forms */
.person-header { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.person-photo { width: 86px; height: 86px; border-radius: 12px; object-fit: cover; background: #dde2de; border: 1px solid var(--border); }
.person-photo.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.person-header h1 { margin: 0; font-size: 21px; }
.person-header .sub { color: var(--muted); font-size: 12px; margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px,1fr)); gap: 11px; }
.form-grid label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-weight: 650; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fbfcfb; }
.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }
.doc-row:last-child { border-bottom: none; }
.doc-row .doc-name { flex: 1; min-width: 220px; }
.doc-row .doc-meta { color: var(--muted); font-size: 11px; }
.doc-row .doc-controls { display: flex; gap: 7px; align-items: center; }
.tabs { display: flex; gap: 2px; margin-bottom: 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { padding: 9px 13px; background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--accent); font-weight: 750; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,23,19,.55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 16px; padding: 21px; width: 520px; max-width: 92vw; max-height: 86vh; overflow: auto; box-shadow: 0 25px 70px rgba(0,0,0,.24); }
.modal h2 { margin-top: 0; font-size: 18px; }
.modal .actions, .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.muted { color: var(--muted); }
.empty-state { text-align: center; padding: 34px 0; color: var(--muted); }
.empty-state.good { color: var(--ok); font-weight: 700; }

@media (display-mode: standalone) { [data-install-app] { display: none !important; } }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20; flex-direction: row; align-items: center;
    padding: 7px 8px; overflow-x: auto; border-bottom: 1px solid rgba(255,255,255,.12);
  }
  .side-brand { border: 0; padding: 0 5px 0 0; min-width: max-content; }
  .side-mark { width: 34px; height: 34px; border-radius: 9px; font-size: 12px; }
  .side-brand > div:last-child, .side-section, .sidebar .logout, .sidebar .install-area { display: none; }
  .sidebar nav { display: flex; flex: 1; justify-content: flex-start; gap: 2px; }
  .sidebar nav a { flex-direction: column; gap: 2px; min-width: 72px; padding: 5px 7px; margin: 0; font-size: 10px; }
  .nav-icon { width: 23px; height: 21px; background: transparent; }
  .sidebar nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .main { padding: 20px 14px 42px; width: 100%; }
  .tactical-stats { grid-template-columns: repeat(2, minmax(130px,1fr)); }
  .page-head { align-items: center; }
  .page-head p { max-width: 260px; }
  .card { overflow-x: auto; padding: 13px; }
  table { min-width: 620px; }
  .person-header { flex-wrap: wrap; }
  .person-header > div[style] { margin-inline-start: 0 !important; width: 100%; }
}

@media (max-width: 520px) {
  .login-screen { padding: 14px; }
  .login-box { width: 100%; padding: 26px 20px 22px; }
  .main h1 { font-size: 22px; }
  .tactical-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-tile { padding: 13px; }
  .stat-tile .num { font-size: 24px; }
  .command-strip { align-items: flex-start; }
  .command-strip > div:first-child { flex-direction: column; gap: 3px; }
  .search-wide { min-width: 100%; }
  .page-head .btn.primary { white-space: nowrap; }
}

/* License gallery */
.person-identity { min-width: 0; }
.person-quick-status { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 9px; }
.quick-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 8px; background: #f3f5f3; border: 1px solid var(--border); color: #59645f; font-size: 11px; }
.quick-chip.ok { background: var(--ok-bg); color: var(--ok); border-color: #cce3d5; }
.quick-chip.warn { background: var(--soon-bg); color: var(--soon); border-color: #ecdcb9; }
.license-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.license-section-head h2 { margin-top: 3px; font-size: 18px; }
.license-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.license-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 12px; box-shadow: 0 5px 18px rgba(20,45,37,.04); min-width: 0; }
.license-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.license-card-head > div { display: flex; align-items: center; gap: 8px; min-width: 0; }
.license-type { display: inline-grid; place-items: center; min-width: 42px; height: 25px; padding: 0 8px; border-radius: 7px; background: var(--brand-dark); color: #fff; font-size: 10px; font-weight: 800; }
.license-meta { color: var(--muted); font-size: 11.5px; margin-bottom: 9px; }
.license-image-link { display: block; background: #e8eeeb; border: 1px solid #d9e1dc; border-radius: 10px; overflow: hidden; }
.license-image { display: block; width: 100%; aspect-ratio: 1011 / 638; object-fit: contain; background: #dbe7e1; }
.license-actions { display: flex; justify-content: flex-end; margin-top: 9px; }

@media (max-width: 700px) {
  .license-grid { grid-template-columns: 1fr; }
  .license-card { padding: 9px; }
  .license-card-head { align-items: flex-start; }
  .person-quick-status { width: 100%; }
}
