/* ==========================================================================
   Nexoria — Mobile-App Design System
   Mobile-first. Looks and behaves like a native app shell.
   ========================================================================== */

/* Nexoria brand theme: near-black + gold, matching the app logo. */
:root {
  --color-bg: #131418;
  --color-surface: #1b1d23;
  --color-surface-alt: #22242b;
  --color-primary: #c9a24e;
  --color-primary-dark: #a9843a;
  --color-primary-light: #3a331f;
  --color-on-primary: #14151a;
  --color-success: #3ecf8e;
  --color-danger: #f0605f;
  --color-warning: #e0ab3f;
  --color-text: #f2efe8;
  --color-text-muted: #9a978f;
  --color-border: #2c2e35;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-elevated: 0 10px 28px rgba(0, 0, 0, 0.55);
  --nav-height: 64px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-size: 16px;
}

/* Optional lighter variant for users whose system prefers light mode —
   still gold-on-dark-surface to stay on-brand, just slightly brighter. */
@media (prefers-color-scheme: light) {
  :root {
    --color-bg: #16181e;
    --color-surface: #1e2028;
    --color-surface-alt: #262933;
    --color-text: #f5f3ee;
    --color-text-muted: #a8a59c;
    --color-border: #33363f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-top: var(--safe-top);
}

body[dir="rtl"] { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }

a { text-decoration: none; color: inherit; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

/* ---------------------------------------------------------------------- */
/* App shell                                                                */
/* ---------------------------------------------------------------------- */

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--color-bg);
  position: relative;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  animation: nx-fade-in 0.16s ease;
}

.auth-screen { animation: nx-fade-in 0.16s ease; }

@keyframes nx-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 481px) {
  .app-shell {
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
    border-inline: 1px solid var(--color-border);
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.topbar .icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-bg);
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
}

.content {
  padding: 16px;
  padding-bottom: 24px;
}

/* ---------------------------------------------------------------------- */
/* Bottom nav (app-like tab bar)                                           */
/* ---------------------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  color: var(--color-text-muted);
  padding: 6px 0;
}

.bottom-nav a .nav-icon { font-size: 1.35rem; line-height: 1; }

.bottom-nav a.active { color: var(--color-primary); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Cards                                                                    */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

.stat-tile.accent { border-color: var(--color-primary); }

.stat-tile .label {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 1.35rem;
  font-weight: 700;
}

.stat-tile.accent { background: var(--color-primary); color: var(--color-on-primary); }
.stat-tile.accent .label { color: rgba(20,21,26,0.65); }

/* ---------------------------------------------------------------------- */
/* Forms                                                                    */
/* ---------------------------------------------------------------------- */

.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.segmented {
  display: flex;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.segmented input { display: none; }

.segmented label {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  border-radius: var(--radius-sm);
  margin: 0;
  cursor: pointer;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
}

.segmented input:checked + label {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--color-border); color: var(--color-text); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 0.82rem; border-radius: var(--radius-sm); }

.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  inset-inline-end: calc(50% - 240px + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border: none;
  font-size: 1.6rem;
  box-shadow: var(--shadow-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  cursor: pointer;
}

@media (max-width: 480px) {
  .fab { inset-inline-end: 16px; }
}

/* ---------------------------------------------------------------------- */
/* Lists / tables                                                           */
/* ---------------------------------------------------------------------- */

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}

.list-item:last-child { border-bottom: none; }

.list-item .title { font-weight: 600; }
.list-item .subtitle { font-size: 0.78rem; color: var(--color-text-muted); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.68rem;
  font-weight: 700;
}

.badge-success { background: rgba(23,178,106,0.15); color: var(--color-success); }
.badge-danger { background: rgba(229,72,77,0.15); color: var(--color-danger); }
.badge-warning { background: rgba(245,165,36,0.15); color: var(--color-warning); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; }

/* ---------------------------------------------------------------------- */
/* Auth screens                                                             */
/* ---------------------------------------------------------------------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 480px;
  margin: 0 auto;
}

.auth-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: #131418;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.auth-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-title { text-align: center; font-size: 1.4rem; font-weight: 800; margin: 0 0 4px; }
.auth-subtitle { text-align: center; color: var(--color-text-muted); margin: 0 0 28px; font-size: 0.9rem; }

.lang-switch {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.lang-switch button {
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.lang-switch button.active {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.alert-error { background: rgba(229,72,77,0.12); color: var(--color-danger); }
.alert-success { background: rgba(23,178,106,0.12); color: var(--color-success); }

/* ---------------------------------------------------------------------- */
/* Modal / sheet                                                            */
/* ---------------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
  display: none;
}

.sheet-backdrop.open { display: block; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom));
  z-index: 41;
  transition: transform 0.25s ease;
  max-height: 85vh;
  overflow-y: auto;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--color-border);
  border-radius: 4px;
  margin: 0 auto 16px;
}

/* ---------------------------------------------------------------------- */
/* Utilities                                                                */
/* ---------------------------------------------------------------------- */

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.text-sm { font-size: 0.82rem; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }
.empty-state .emoji { font-size: 2.4rem; margin-bottom: 10px; }

.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

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