/* =====================================================================
   Glass Sorting Finder — Main Stylesheet
   Supports RTL (Arabic) and LTR (English)
   Mobile-first design
   ===================================================================== */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #1a73e8;
  --primary-dk: #1558b0;
  --success:    #1e8e3e;
  --danger:     #d93025;
  --warning:    #f9a825;
  --info:       #0097a7;
  --bg:         #f4f6fb;
  --surface:    #ffffff;
  --border:     #dde2ec;
  --text:       #202124;
  --muted:      #5f6368;
  --radius:     12px;
  --shadow:     0 2px 12px rgba(0,0,0,.10);
  --font-ar:    'Segoe UI', Tahoma, Arial, sans-serif;
  --font-en:    'Segoe UI', Roboto, Arial, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font-en);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body.lang-ar { font-family: var(--font-ar); }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: background .2s, transform .1s;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  min-height: 44px;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); text-decoration: none; color:#fff; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e8eaed; text-decoration: none; }
.btn-lg  { padding: 14px 28px; font-size: clamp(1rem, 4.5vw, 1.1rem); border-radius: 10px; min-height: 52px; }
.btn-full { width: 100%; }

/* ---- Alerts ---- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: .95rem;
}
.alert-error   { background: #fdecea; color: var(--danger);  border: 1px solid #f5c6c4; }
.alert-success { background: #e6f4ea; color: var(--success); border: 1px solid #b7e0c2; }
.alert-info    { background: #e1f6f8; color: var(--info);    border: 1px solid #a5d8de; }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: .95rem;
  color: var(--text);
}
.required { color: var(--danger); }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,.15);
}
.form-hint { display: block; margin-top: 4px; font-size: .82rem; color: var(--muted); }

/* Custom select arrow */
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%235f6368'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-left: 36px;
}
[dir='ltr'] .form-select {
  background-position: right 14px center;
  padding-right: 36px;
  padding-left: 14px;
}

/* =====================================================================
   WORKER PAGE
   ===================================================================== */

/* Desktop: blue background visible around the card */
body.worker-page {
  overflow: hidden;
  background: var(--primary);
}

/* position:fixed with left/right/auto — works on Chrome+Safari+RTL/LTR */
.worker-wrapper {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: 0 0 80px rgba(0,0,0,.3);
  overflow: hidden;
}

/* ── Header ── */
.worker-header {
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  padding: 16px 18px 14px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.app-title {
  font-size: clamp(1rem, 5vw, 1.25rem);
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-subtitle {
  font-size: .88rem;
  opacity: .85;
  margin: 7px 0 0;
  text-align: center;
}

/* Language switcher */
.lang-switcher { display: flex; gap: 8px; }
.lang-btn {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 6px 14px;
  background: rgba(255,255,255,.2);
  border-radius: 20px;
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.4);
  transition: background .2s;
  text-decoration: none;
  touch-action: manipulation;
}
.lang-btn:hover { background: rgba(255,255,255,.35); text-decoration: none; color: #fff; }

/* ── Scrollable main — min-height:0 + width:100% critical for Chrome flex scroll —─ */
.worker-main {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Search form ── */
.search-form {
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
}
.form-group { margin-bottom: 16px; }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.form-actions .btn { flex: 1; }

/* Worker input overrides: 16px prevents iOS auto-zoom */
.worker-main .form-label  { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.worker-main .form-input,
.worker-main .form-select { font-size: 16px; min-height: 52px; padding: 14px 16px; border-radius: 10px; }
.worker-main .form-select { padding-left: 40px; }
[dir='ltr'] .worker-main .form-select { padding-right: 40px; padding-left: 16px; }
.worker-main .form-hint   { font-size: .85rem; }
.worker-main .btn-lg      { font-size: 1.05rem; min-height: 52px; border-radius: 12px; touch-action: manipulation; }

/* ── Results ── */
@keyframes wSlideUp { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.result-section { animation: wSlideUp .2s ease; }

.result-error {
  padding: 40px 20px;
  text-align: center;
  border-top: 4px solid var(--danger);
}
.result-icon { font-size: 3rem; line-height: 1; display: block; }
.result-error-text { font-size: clamp(1.1rem, 5vw, 1.3rem); font-weight: 700; color: var(--danger); margin: 12px 0 6px; }
.result-hint { font-size: clamp(.88rem, 4vw, 1rem); color: var(--muted); }

.result-success {
  padding: 24px 20px;
  text-align: center;
  border-top: 4px solid var(--success);
  border-bottom: 1px solid var(--border);
}
.result-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: var(--success);
  color: #fff;
  border-radius: 14px;
  padding: 8px 22px;
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.5;
}
.result-label  { font-weight: 700; }
.result-code   { font-size: .82rem; opacity: .85; font-weight: 400; }

.result-apartments { width: 100%; }
.apartment-card {
  background: #eef3fe;
  border: 2.5px solid var(--primary);
  border-radius: 14px;
  padding: 12px 18px;
  display: inline-block;
  margin: 5px;
}
.apartment-card.single {
  display: block;
  width: min(80%, 240px);
  margin: 0 auto;
  padding: 22px 20px;
  border-width: 3px;
}
.apt-number {
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  display: block;
  letter-spacing: -.5px;
}
.apartment-card.single .apt-number { font-size: clamp(4rem, 20vw, 6rem); }
.apartments-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 4px 0;
}
.result-area  { margin-top: 16px; font-size: 1rem; color: var(--muted); }
.result-notes {
  margin-top: 10px;
  font-size: .95rem;
  color: var(--muted);
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  text-align: start;
}
.notes-label { font-weight: 600; margin-inline-end: 4px; }

/* ── Footer ── */
.worker-footer {
  flex-shrink: 0;
  padding: 10px 18px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.admin-link { font-size: .82rem; color: var(--muted); touch-action: manipulation; }

@media (max-width: 520px) {
  .worker-wrapper { box-shadow: none; }
  .worker-header { padding: 12px 14px 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
}

/* =====================================================================
   LOGIN PAGE
   ===================================================================== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 8px; }
.login-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { font-size: 1rem; color: var(--muted); margin-bottom: 24px; }
.login-form { text-align: start; margin-bottom: 16px; }
.login-lang { margin-top: 16px; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 480px) {
  .login-box { padding: 26px 18px; }
}

/* =====================================================================
   ADMIN FORM EXTENSIONS
   ===================================================================== */
.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.form-row .form-group {
  flex: 1;
  min-width: 160px;
}
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-3 { margin-bottom: 16px; }
.btn-sm { padding: 7px 14px; font-size: .875rem; border-radius: 6px; }

/* Lookup result box */
.lookup-result-box {
  background: #e8f5e9;
  border: 1.5px solid #81c784;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.lookup-error-box {
  background: #fdecea;
  border: 1.5px solid #ef9a9a;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  color: var(--danger);
  font-weight: 600;
}
.lookup-label { font-weight: 600; color: var(--muted); font-size: .9rem; margin-inline-end: 4px; }
.lookup-value { font-size: 1.1rem; font-weight: 700; color: var(--text); }

/* Badge for sizes */
.badge-size {
  display: inline-block;
  background: #e8eaf6;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: .85rem;
  font-weight: 600;
  color: #3949ab;
  letter-spacing: .3px;
}

/* Grand total row in reports */
.total-row td {
  background: var(--bg);
  border-top: 2px solid var(--border);
  font-weight: 700;
}

/* Nav group labels in sidebar */
.nav-group-label {
  padding: 8px 16px 2px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(255,255,255,.45);
  margin-top: 4px;
}
.nav-divider {
  border-top: 1px solid rgba(255,255,255,.15);
  margin: 8px 16px;
}

