:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-soft: #eef2ff;
    --success: #0a7c3a;
    --warn:    #b45309;
    --error:   #b91c1c;
    --bg:        #f5f7fb;
    --bg-card:   #ffffff;
    --border:    #e4e7ec;
    --text:      #0f172a;
    --text-secondary: #475569;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow:    0 1px 3px rgba(15,23,42,.08), 0 4px 12px rgba(15,23,42,.05);
    --shadow-lg: 0 4px 8px rgba(15,23,42,.08), 0 16px 32px rgba(15,23,42,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
html[dir="rtl"] body { direction: rtl; text-align: right; line-height: 1.55; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
small { color: var(--text-secondary); }

/* ── boot splash ── */
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px; background: linear-gradient(180deg, #fff 0%, var(--bg) 100%); }
.boot-inner { text-align: center; max-width: 22.5rem; }
.boot-spinner { width: 56px; height: 56px; border: 5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 18px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot p { margin: 0 0 6px; font-weight: 600; color: var(--text); }
.boot small { color: var(--text-secondary); }

/* ── app shell ── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-header {
    background: var(--primary);
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 1px 0 rgba(255,255,255,.08), 0 2px 8px rgba(15,23,42,.12);
    padding-top: max(10px, env(safe-area-inset-top));
}
.app-header .brand { display: flex; align-items: center; gap: 10px; color: white; min-width: 0; min-height: 44px; }
.app-header .brand img { height: 28px; width: auto; display: block; }
.app-header .brand .title { font-weight: 700; font-size: 0.9375rem; line-height: 1; }
.app-header .brand .sub { font-size: 0.6875rem; opacity: .85; line-height: 1.2; }
.app-header .header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; max-width: 58%; }
.app-header .who { font-size: 0.75rem; opacity: .92; text-align: end; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .who .name { font-weight: 600; display: block; line-height: 1.2; }
.app-header .who .role { opacity: .75; font-size: 0.625rem; text-transform: uppercase; letter-spacing: .5px; }

.app-main { flex: 1; padding: 16px; padding-bottom: 6rem; max-width: 45rem; width: 100%; min-width: 0; margin: 0 auto; }
.app-main h1 { font-size: 1.375rem; margin: 8px 0 4px; font-weight: 700; }
.app-main h1 .h-sub { display: block; font-size: 0.8125rem; font-weight: 400; color: var(--text-secondary); margin-top: 2px; }

/* ── bottom nav ── */
.app-bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: white;
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-around;
    padding: 6px 4px env(safe-area-inset-bottom, 8px) 4px;
    z-index: 10;
    box-shadow: 0 -2px 12px rgba(15,23,42,.06);
}
.app-bottom-nav a, .app-bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 6px 8px; font-size: 0.6875rem; color: var(--text-secondary);
    border-radius: 10px; min-width: 0; flex: 1 1 0;
    background: none; border: 0;
    transition: color .15s, background .15s;
}
.app-bottom-nav a span, .app-bottom-nav button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-bottom-nav a.active { color: var(--primary); background: var(--primary-soft); }
.app-bottom-nav a i, .app-bottom-nav button i { font-size: 1.125rem; }

/* ── card / form / button ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow-wrap: anywhere;
}
.card fieldset { min-width: 0; }
.card table { max-width: 100%; }
.card-title {
    font-weight: 700;
    margin: 0 0 12px;
    display: flex; align-items: center; gap: 8px;
    font-size: 0.9375rem;
    color: var(--text);
}
.card-title i { color: var(--primary); }
.card-lead { color: var(--text-secondary); font-size: 0.8125rem; margin: -4px 0 12px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.8125rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;            /* 16px → iOS won't zoom on focus */
    background: white;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(30,64,175,.15); }
.ltr-input { direction: ltr; text-align: left; unicode-bidi: isolate; }
.confirmation-phrase, bdi { unicode-bidi: isolate; }
.confirmation-phrase { display: inline-block; max-width: 100%; overflow-wrap: anywhere; font-weight: 700; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1 1 0; min-width: min(140px, 100%); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 18px; border: 0; border-radius: 10px;
    font-size: 0.875rem; font-weight: 600;
    transition: transform .05s, background .15s, box-shadow .15s;
    white-space: normal; text-align: center; line-height: 1.3;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 6px rgba(30,64,175,.25); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: white; color: var(--primary); border: 1px solid var(--primary); }
.btn-ghost   { background: transparent; color: var(--text-secondary); }
.btn-block   { display: flex; width: 100%; }
.btn-sm      { padding: 8px 12px; font-size: 0.8125rem; }
.btn-lg      { padding: 14px 22px; font-size: 0.9375rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ── badges & list rows ── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 0.6875rem; font-weight: 700;
    background: var(--primary-soft); color: var(--primary);
}
.badge.warn  { background: #fef3c7; color: var(--warn); }
.badge.ok    { background: #dcfce7; color: var(--success); }
.badge.err   { background: #fee2e2; color: var(--error); }
.badge.muted { background: #e2e8f0; color: var(--text-secondary); }

.list-row {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    transition: background .15s;
    cursor: pointer;
}
.list-row:hover { background: #f9fafb; }
.list-row:last-child { border-bottom: 0; }
.list-row .icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 1rem;
}
.list-row .meta { flex: 1; min-width: 0; }
.list-row .meta .title { font-weight: 600; line-height: 1.3; color: var(--text); }
.list-row .meta .title small { color: var(--text-secondary); font-weight: 400; margin-inline-start: 6px; font-size: 0.75rem; }
.list-row .meta .sub { color: var(--text-secondary); font-size: 0.75rem; margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.list-row .chev { color: var(--text-secondary); opacity: .5; }

/* ── empty state ── */
.empty {
    text-align: center; padding: 36px 20px;
}
.empty .ico { font-size: 2.75rem; color: #cbd5e1; margin-bottom: 12px; display: block; }
.empty h3 { margin: 0 0 6px; font-size: 1rem; }
.empty p  { color: var(--text-secondary); margin: 0 0 16px; font-size: 0.8438rem; }

/* ── floating sync badge ── */
.sync-badge {
    position: fixed; bottom: 5.5rem; inset-inline-end: 16px; z-index: 20; min-height: 44px;
    background: white; border: 1px solid var(--border);
    border-radius: 999px; padding: 8px 14px;
    box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 8px;
    font-size: 0.8125rem; font-weight: 600;
    cursor: pointer; font-family: inherit;
}
.sync-badge.warn { color: var(--warn);  border-color: rgba(180,83,9,.4);  background: #fffbeb; }
.sync-badge.err  { color: var(--error); border-color: rgba(185,28,28,.4); background: #fef2f2; }
.sync-badge.ok   { color: var(--success); border-color: rgba(10,124,58,.4); background: #f0fdf4; }
.sync-badge .pulse { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* ── alerts ── */
.alert {
    padding: 12px 14px; border-radius: 10px; margin-bottom: 14px;
    font-size: 0.8125rem; border: 1px solid;
    display: flex; align-items: flex-start; gap: 10px;
}
.alert i { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.alert.info { background: var(--primary-soft); color: var(--primary); border-color: rgba(30,64,175,.2); }
.alert.warn { background: #fffbeb; color: var(--warn);    border-color: rgba(180,83,9,.3); }
.alert.err  { background: #fef2f2; color: var(--error);   border-color: rgba(185,28,28,.3); }
.alert.ok   { background: #f0fdf4; color: var(--success); border-color: rgba(10,124,58,.3); }

.muted { color: var(--text-secondary); }
.hr { height: 1px; background: var(--border); margin: 14px 0; }

/* ── search bar ── */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-wrap .search-icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 0.875rem; pointer-events: none; }
.search-wrap input.form-control { padding-inline-start: 36px; }

/* ── login page ── */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(165deg, #1e3a8a 0%, #1e40af 60%, #2563eb 100%);
    display: flex; flex-direction: column;
    padding: 32px 20px; padding-top: max(32px, env(safe-area-inset-top));
}
.auth-page .auth-hero { text-align: center; color: white; margin-bottom: 28px; }
.auth-page .auth-hero img { height: 40px; margin-bottom: 14px; filter: brightness(0) invert(1); }
.auth-page .auth-hero h1 { margin: 0 0 4px; font-size: 1.375rem; font-weight: 700; }
.auth-page .auth-hero p  { margin: 0; font-size: 0.8125rem; opacity: .85; }
.auth-page .auth-card {
    background: white; border-radius: 16px; padding: 24px 20px;
    box-shadow: var(--shadow-lg);
    max-width: 23.75rem; width: 100%; margin: 0 auto;
}
.auth-page .auth-foot { color: rgba(255,255,255,.7); font-size: 0.75rem; text-align: center; margin-top: 22px; }
.auth-page .auth-foot i { margin-inline-end: 6px; }

/* ── language direction and switch ── */
.no-chrome-layout { min-height: 100%; position: relative; }
.language-toggle-slot { position: fixed; inset-block-start: max(12px, env(safe-area-inset-top)); inset-inline-end: 12px; z-index: 50; }
.language-toggle {
    appearance: none; border: 1px solid rgba(255,255,255,.55); border-radius: 999px;
    background: rgba(15,23,42,.22); color: white; min-width: 72px; min-height: 44px;
    padding: 7px 12px; font-size: 0.75rem; font-weight: 700; line-height: 1.2;
    white-space: nowrap; backdrop-filter: blur(4px);
}
.language-toggle:focus-visible { outline: 3px solid #fbbf24; outline-offset: 2px; }
.app-header .language-toggle { min-width: 58px; padding: 6px 9px; }
html[dir="rtl"] .page-title-row .back i { transform: scaleX(-1); }
html[dir="rtl"] .rtl-mirror,
html[dir="rtl"] .list-row .chev { transform: scaleX(-1); }
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[inputmode="tel"],
html[dir="rtl"] input[inputmode="decimal"],
html[dir="rtl"] input[inputmode="numeric"] { direction: ltr; text-align: left; unicode-bidi: isolate; }

code, .numeric-value { direction: ltr; unicode-bidi: isolate; }

/* ── form-as-card layout for full-page forms (CustomerNew, ApplicationNew) ── */
.page-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.page-title-row .back { background: white; border: 1px solid var(--border); color: var(--text-secondary); width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.page-title-row h1 { margin: 0; flex: 1; font-size: 1.1875rem; }

/* ── post-create success splash ── */
.success-card { text-align: center; padding: 28px 20px; }
.success-card .check { width: 64px; height: 64px; border-radius: 50%; background: #dcfce7; color: var(--success); display: inline-flex; align-items: center; justify-content: center; font-size: 1.875rem; margin-bottom: 14px; }
.success-card h2 { margin: 0 0 6px; font-size: 1.125rem; }
.success-card p  { color: var(--text-secondary); margin: 0 0 18px; font-size: 0.8438rem; }

/* ── prominent action card grid (used on customer detail) ── */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.action-tile {
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 12px;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    color: var(--text); font-weight: 600; text-align: center;
    transition: border-color .15s, box-shadow .15s, transform .05s;
    cursor: pointer;
}
.action-tile:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.action-tile:active { transform: scale(.98); }
.action-tile .ico { width: 44px; height: 44px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.125rem; }
.action-tile span { font-size: 0.8125rem; line-height: 1.3; }

/* ── per-customer action bar at top of detail ── */
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.action-bar .btn { flex: 1 1 0; min-width: min(140px, 100%); }
.device-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.device-actions .btn { flex: 1 1 180px; min-width: 0; }

/* ── responsive niceties ── */
@media (min-width: 720px) {
    .app-main { padding-top: 24px; }
    .auth-page .auth-card { padding: 32px 28px; }
}

@media (max-width: 390px) {
    .app-header { padding-inline: 10px; gap: 8px; }
    .app-header .brand { gap: 7px; }
    .app-header .brand img { height: 24px; }
    .app-header .brand .sub { display: none; }
    .app-header .header-actions { max-width: 62%; gap: 5px; }
    .app-header .who .role { display: none; }
    .app-bottom-nav a, .app-bottom-nav button { padding-inline: 3px; font-size: 0.625rem; }
    .auth-page { padding-inline: 14px; }
    .auth-page .auth-card { padding-inline: 16px; }
    .language-toggle-slot { inset-inline-end: 8px; }
}

/* ── capture forms (Services/Capture, Shared/CaptureFormStatus) ── */
.req { color: var(--error); font-weight: 700; margin-inline-start: 2px; }
.required-legend { font-size: 0.8125rem; color: var(--text-secondary); margin: 0 0 10px; }
.label-text { display: block; font-size: 0.8125rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.form-control[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 3px rgba(185,28,28,.12); }
.error-summary p { margin: 0; }
.error-summary ul { margin: 6px 0 0; padding-inline-start: 18px; }
.error-summary a { color: inherit; text-decoration: underline; }
.draft-notice { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.checkbox-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.checkbox-row input[type="checkbox"] { width: 24px; height: 24px; flex-shrink: 0; }
.checkbox-row label { margin: 0; }
.list-row-wrap { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.list-row-wrap:last-child { border-bottom: 0; }
.list-row-wrap .list-row { flex: 1; min-width: 0; border-bottom: 0; }
.row-delete { color: var(--error); padding: 0 14px; border-radius: 0; }
button.action-tile { font: inherit; width: 100%; }
/* Minimum 44×44 px touch targets (Google / WCAG 2.5.5 guidance). */
.btn, .btn-xs, .page-title-row .back { min-height: 44px; min-width: 44px; }
/* Every other tap target reaches 44×44 too: header and bottom navigation,
   language switch, sync badge, disclosure rows, list rows. */
.language-toggle, .sync-badge, .app-bottom-nav a, .app-bottom-nav button, .list-row { min-height: 44px; }
details > summary { min-height: 44px; display: flex; align-items: center; gap: 6px; }
select.form-control, input.form-control { min-height: 44px; }
/* Text scaling: no root font size is set (the reader's browser setting
   applies), type is in rem, and long words wrap instead of widening the
   page at 320 px and 200% text. */
.app-main, .card, .alert, .list-row .meta { overflow-wrap: anywhere; }
.page-title-row .back { width: 44px; height: 44px; }
.btn-xs { padding: 8px 12px; font-size: 0.8125rem; }
