/* ============================================================
   TY Rental Admin — Professional SPA styles
   Brand: Navy #002D4B · Lime #89B932 · Light surfaces
   ============================================================ */

:root {
  --navy: #002d4b;
  --navy-2: #013a5c;
  --lime: #89b932;
  --lime-dark: #6f9a22;
  --lime-soft: rgba(137, 185, 50, 0.14);
  --bg: #f3f6f1;
  --bg-2: #e8efe3;
  --surface: #ffffff;
  --ink: #0c2233;
  --muted: #5a7183;
  --line: rgba(0, 45, 75, 0.12);
  --line-strong: rgba(0, 45, 75, 0.22);
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --ok: #027a48;
  --ok-soft: #ecfdf3;
  --info: #026aa2;
  --info-soft: #f0f9ff;
  --shadow: 0 10px 30px rgba(0, 45, 75, 0.08);
  --shadow-lg: 0 24px 60px rgba(0, 45, 75, 0.16);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 268px;
  --topbar-h: 72px;
  --font: "IBM Plex Sans Arabic", "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--navy); }

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 15% 10%, rgba(137, 185, 50, 0.22), transparent 42%),
    radial-gradient(ellipse at 85% 90%, rgba(137, 185, 50, 0.12), transparent 40%),
    linear-gradient(145deg, #001e33 0%, var(--navy) 55%, #014066 100%);
}

.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border-radius: 22px;
  padding: 1.75rem 1.75rem 1.4rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.login-mark,
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--lime), #a8d04a);
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 18px rgba(137, 185, 50, 0.35);
}

.login-title {
  font-weight: 800;
  color: var(--navy);
  font-size: 1.15rem;
}

.login-sub,
.login-hint {
  color: var(--muted);
  font-size: 0.92rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
  color: var(--navy);
}

.login-card label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  font-weight: 600;
  color: var(--navy);
}

.login-card input,
.field input,
.field select,
.field textarea,
.toolbar select,
.toolbar input,
.filters select,
.filters input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.login-card input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.toolbar select:focus,
.toolbar input:focus {
  outline: none;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px var(--lime-soft);
}

.lang-pill {
  position: absolute;
  top: 1rem;
  inset-inline-end: 1rem;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-weight: 700;
  color: var(--navy);
}

/* ---------- Shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, var(--navy) 0%, #001a2d 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.9rem;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.55rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0.75rem;
}

.brand-text strong {
  display: block;
  font-size: 1.05rem;
}

.brand-text small {
  color: rgba(255, 255, 255, 0.65);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: auto;
  flex: 1;
  padding-inline: 0.15rem;
}

.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  text-align: start;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.86);
  padding: 0.72rem 0.85rem;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.sidebar-nav button.is-denied,
.sidebar-nav button[hidden] {
  display: none !important;
}

.sidebar-nav button:hover {
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-nav button.active {
  background: var(--lime-soft);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(137, 185, 50, 0.35);
}

.nav-ico {
  width: 1.35rem;
  text-align: center;
  opacity: 0.85;
  font-size: 0.95rem;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 0.65rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.45rem;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--lime);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.user-chip strong {
  display: block;
  font-size: 0.92rem;
}

.user-chip small {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.78rem;
}

.main-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(circle at 100% 0%, rgba(137, 185, 50, 0.08), transparent 28%),
    var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.4rem;
  background: rgba(243, 246, 241, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.28rem;
  color: var(--navy);
}

.topbar-sub {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.api-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
}

.content {
  padding: 1.15rem 1.4rem 2.2rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 999px;
  padding: 0.62rem 1.05rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform .12s, background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--lime);
  color: var(--navy);
  box-shadow: 0 6px 16px rgba(137, 185, 50, 0.28);
}

.btn-primary:hover { background: var(--lime-dark); color: #fff; }

.btn-ghost {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--navy);
}

.btn-ghost:hover { background: #f7faf4; }

.sidebar .btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-warn {
  background: #f79009;
  color: #fff;
}

.btn-info {
  background: var(--navy);
  color: #fff;
}

.btn-sm {
  padding: 0.38rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 999px;
}

.btn-block { width: 100%; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--navy);
}

#sidebarToggle { display: none; }

/* ---------- Cards / Panels ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  inset-inline-end: -18px;
  top: -18px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--lime-soft);
}

.kpi-card .label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.kpi-card .value {
  margin-top: 0.4rem;
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.02em;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel + .panel,
.chart-grid + .panel,
.kpi-grid + .chart-grid,
.kpi-grid + .panel {
  margin-top: 1rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdf8, #fff);
}

.panel-head h3 {
  margin: 0;
  font-size: 1.02rem;
  color: var(--navy);
}

.panel-body { padding: 1rem 1.1rem; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  min-height: 300px;
}

.chart-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.98rem;
  color: var(--navy);
}

.chart-wrap {
  position: relative;
  height: 230px;
}

/* ---------- Toolbar / Filters ---------- */
.page-toolbar,
.filters,
.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.page-toolbar .spacer,
.report-toolbar .spacer { flex: 1; }

.filter-field {
  display: grid;
  gap: 0.3rem;
  min-width: 150px;
}

.filter-field span {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding: 0.35rem;
  background: #e9f0e4;
  border-radius: 999px;
  width: fit-content;
  max-width: 100%;
}

.tabs button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
}

.tabs button.active {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(0, 45, 75, 0.08);
}

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

table.data-table th,
table.data-table td {
  padding: 0.82rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: start;
  font-size: 0.92rem;
  vertical-align: middle;
}

table.data-table th {
  background: #f7faf4;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

table.data-table tbody tr:hover { background: #fafcf7; }

table.data-table .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.totals-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: #f7faf4;
  border-top: 1px solid var(--line);
  font-weight: 700;
  color: var(--navy);
}

.totals-bar span { color: var(--muted); font-weight: 600; margin-inline-end: 0.35rem; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: #eef2f6;
  color: var(--navy);
  white-space: nowrap;
}

.pill-active,
.pill-posted,
.pill-allocated,
.pill-available,
.pill-paid { background: var(--ok-soft); color: var(--ok); }

.pill-draft,
.pill-reserved,
.pill-due,
.pill-partially_paid { background: var(--info-soft); color: var(--info); }

.pill-expiring,
.pill-suspended,
.pill-maintenance,
.pill-temporarily_closed { background: var(--warn-soft); color: var(--warn); }

.pill-overdue,
.pill-void,
.pill-inactive,
.pill-blocked,
.pill-vacated,
.pill-cancelled,
.pill-not_rentable { background: var(--danger-soft); color: var(--danger); }

.pill-rented { background: var(--lime-soft); color: var(--navy); }

/* ---------- Empty / Loading ---------- */
.empty-state {
  text-align: center;
  padding: 2.4rem 1.2rem;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--navy);
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
}

.skeleton {
  background: linear-gradient(90deg, #e8efe3 25%, #f5f8f2 50%, #e8efe3 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius);
  min-height: 96px;
}

.skeleton.row { min-height: 48px; margin-bottom: 0.55rem; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.form-grid .full { grid-column: 1 / -1; }

.field {
  display: grid;
  gap: 0.35rem;
}

.field > span {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.9rem;
}

.field .hint { color: var(--muted); font-size: 0.8rem; font-weight: 500; }

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
}

.form-error {
  color: var(--danger);
  margin: 0.65rem 0 0;
  font-size: 0.92rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.unit-picker {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow: auto;
}

.unit-picker label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.unit-picker label:last-child { border-bottom: 0; }

.unit-picker input[type="number"] {
  width: 110px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* ---------- Modal / Toast ---------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 20, 35, 0.48);
  backdrop-filter: blur(2px);
}

.modal {
  position: relative;
  width: min(680px, 100%);
  max-height: min(90vh, 900px);
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}

.modal-sm { width: min(420px, 100%); }

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  background: #fafcf7;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--navy);
}

.modal-body {
  padding: 1.1rem 1.15rem;
  overflow: auto;
}

.toast-root {
  position: fixed;
  inset-inline-end: 1rem;
  bottom: 1rem;
  z-index: 120;
  display: grid;
  gap: 0.55rem;
  width: min(360px, calc(100vw - 2rem));
}

.toast {
  background: #fff;
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--navy);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}

.toast.success { border-inline-start-color: var(--lime); }
.toast.error { border-inline-start-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--line);
}

.pagination button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--navy);
}

.pagination button.active,
.pagination button:hover:not(:disabled) {
  background: var(--lime-soft);
  border-color: rgba(137, 185, 50, 0.45);
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pagination .meta {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Detail ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.detail-item {
  background: #f7faf4;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}

.detail-item strong {
  color: var(--navy);
}

/* ---------- RTL / LTR ---------- */
html[dir="ltr"] body { font-family: "IBM Plex Sans", "IBM Plex Sans Arabic", "Segoe UI", sans-serif; }
html[dir="ltr"] .sidebar-nav button,
html[dir="ltr"] table.data-table th,
html[dir="ltr"] table.data-table td { text-align: left; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    transform: translateX(110%);
    transition: transform .2s ease;
    width: min(300px, 86vw);
    box-shadow: var(--shadow-lg);
  }
  html[dir="rtl"] .sidebar { transform: translateX(-110%); }
  .app-shell.sidebar-open .sidebar { transform: none; }
  #sidebarToggle { display: grid; }
  .form-grid,
  .detail-grid,
  .skeleton-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .content { padding: 0.9rem; }
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0.75rem 0.9rem; }
}

.audit-json {
  margin: 0;
  padding: 0.85rem 1rem;
  background: #0b1c28;
  color: #e8f0e4;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  max-height: 50vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
