/* css/style.css - FIXED (theme works from html OR body) */

/* Allow browser UI (inputs/scrollbars) to match theme */
:root { color-scheme: light dark; }

/* ========= Theme tokens ========= */
:root {
  --font: "Cairo", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  /* Light (Green + Cream) */
  --bg: #fff7ed;          /* cream */
  --surface: #ffffff;
  --surface-2: #fffdfa;
  --text: #0f172a;        /* slate */
  --muted: #475569;
  --border: #e5e7eb;
  --primary: #10b981;     /* emerald */
  --primary-2: #059669;   /* darker emerald */
  --danger: #ef4444;
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.08);

  --radius: 16px;
  --radius-sm: 12px;

  --container: 980px;
}

/* Dark mode tokens:
   Support BOTH:
   - html[data-theme="dark"]
   - body[data-theme="dark"]
*/
html[data-theme="dark"],
body[data-theme="dark"] {
  --bg: #060b14;
  --surface: #0b1220;
  --surface-2: #0f1b32;
  --text: #e5e7eb;
  --muted: #9aa4b2;
  --border: rgba(148, 163, 184, 0.18);
  --primary: #34d399;
  --primary-2: #10b981;
  --danger: #f87171;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 30% -10%, rgba(16,185,129,0.18), transparent 60%),
              radial-gradient(900px 500px at 100% 10%, rgba(16,185,129,0.10), transparent 55%),
              var(--bg);
  color: var(--text);
  direction: ltr;
}

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

/* ========= Arabic (optional) =========
   Support BOTH:
   - html[data-lang="ar"]
   - body[data-lang="ar"]
*/
html[data-lang="ar"],
body[data-lang="ar"] {
  direction: rtl;
}

/* Keep layout stable but align text for Arabic */
html[data-lang="ar"] .h1,
html[data-lang="ar"] .p,
html[data-lang="ar"] label,
body[data-lang="ar"] .h1,
body[data-lang="ar"] .p,
body[data-lang="ar"] label {
  text-align: right;
}

/* ========= Layout ========= */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 20px 16px;
}

/* ========= Header ========= */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

html[data-theme="dark"] .header,
body[data-theme="dark"] .header {
  background: rgba(6, 11, 20, 0.65);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
  color: inherit;
}

.brand img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.brand .title {
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.1;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap; /* desktop wrap */
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  user-select: none;
  white-space: nowrap;
}

.icon-btn:hover {
  border-color: rgba(16, 185, 129, 0.55);
  background: rgba(16, 185, 129, 0.08);
}

.icon-btn:active { transform: translateY(1px); }

.icon-btn.danger {
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}
.icon-btn.danger:hover {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.55);
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
}

/* ========= Cards / Surfaces ========= */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.75), rgba(255,255,255,0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

html[data-theme="dark"] .card,
body[data-theme="dark"] .card {
  background: linear-gradient(180deg, rgba(15,27,50,0.75), rgba(11,18,32,0.95));
}

.h1 {
  margin: 0 0 8px 0;
  font-size: clamp(24px, 4vw, 28px); /* mobile responsive */
  letter-spacing: 0.2px;
}

.p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

/* ========= Buttons ========= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(16, 185, 129, 0.35);
  background: var(--primary);
  color: #052016;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
  text-decoration: none;
  white-space: nowrap;
  width: 100%; /* mobile: full width */
}

@media (min-width: 520px) {
  .btn:not([style*="width"]) { width: fit-content; }
}

html[data-theme="dark"] .btn,
body[data-theme="dark"] .btn {
  color: #03130c;
}

.btn:hover { filter: brightness(1.03); }
.btn:active { transform: translateY(1px); }

.btn.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  font-weight: 800;
}

.btn.danger {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger);
  font-weight: 800;
}

/* ========= Forms ========= */
.form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  display: block;
  font-weight: 800;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.55);
  color: var(--text);
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
  background: rgba(0,0,0,0.15);
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(16, 185, 129, 0.7);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
}

textarea { resize: vertical; }

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.row > * { flex: 1; }
.row .fit { flex: 0 0 auto; }

.helper {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.error {
  color: var(--danger);
  font-size: 13px;
  display: none;
  margin-top: 6px;
}
.error.show { display: block; }

.notice {
  border: 1px solid var(--border);
  background: rgba(16, 185, 129, 0.08);
  color: var(--text);
  padding: 12px 12px;
  border-radius: var(--radius);
  font-weight: 800;
  display: none;
}
.notice.show { display: block; }
.notice.bad {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.25);
}

/* ========= Footer ========= */
.footer {
  margin-top: auto;
  padding: 18px 0;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.35);
}

html[data-theme="dark"] .footer,
body[data-theme="dark"] .footer {
  background: rgba(0,0,0,0.10);
}

/* Dark mode: Force all text white */
html[data-theme="dark"] *,
html[data-theme="dark"] *::before,
html[data-theme="dark"] *::after,
body[data-theme="dark"] *,
body[data-theme="dark"] *::before,
body[data-theme="dark"] *::after {
  color: #ffffff !important;
  fill: #ffffff !important;
}

/* Dark mode: Cards lighter */
html[data-theme="dark"] .card,
body[data-theme="dark"] .card {
  background: linear-gradient(180deg, rgba(25,35,55,0.95), rgba(15,25,45,0.98));
  border-color: rgba(255,255,255,0.12);
}

/* ========= Home hero ========= */
.hero {
  padding: clamp(28px, 6vw, 36px) 0 clamp(22px, 5vw, 28px);
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: clamp(16px, 3vw, 24px);
  align-items: stretch;
}

@media (max-width: 860px) {
  .hero-grid { grid-template-columns: 1fr; }
}

.logo-big {
  width: clamp(76px, 12vw, 86px);
  height: clamp(76px, 12vw, 86px);
  object-fit: contain;
}

.cta {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.links {
  margin-top: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
}

/* File list cards (dashboard) */
.files-grid {
  display: grid;
  gap: clamp(12px, 2vw, 16px);
  margin-top: 14px;
}

/* Modal (file preview) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 24px);
}

.modal-content {
  max-width: min(92vw, 860px);
  max-height: 92vh;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* File list row */
.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: clamp(10px, 2vw, 16px);
  padding: 14px;
  border-radius: var(--radius-sm);
}

.file-row > div:first-child {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 800;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  color: var(--muted);
  font-size: 13px;
}

/* Small screens */
@media (max-width: 520px) {
  .container {
    padding: 16px 12px;
  }

  .h1 {
    font-size: clamp(20px, 6vw, 24px);
  }

  .card {
    padding: clamp(16px, 4vw, 20px);
  }

  .header-inner {
    padding-block: clamp(10px, 2vw, 12px);
  }

  .controls {
    gap: 6px;
  }

  .icon-btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  /* File row: stack buttons */
  .file-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .file-row > div:last-child {
    order: 2;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .file-row > div:last-child > * {
    flex: 1;
  }
}

/* Large screens */
@media (min-width: 1200px) {
  :root { --container: 1120px; }
}

/* ===== FIX 2: Dashboard file card overflow (buttons stay inside the card) ===== */
@media (max-width: 520px) {
  #files-list > .card {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  #files-list > .card > div:first-child {
    min-width: 0 !important;
    width: 100% !important;
  }

  #files-list > .card > div:last-child {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: stretch !important;
  }

  #files-list > .card > div:last-child .icon-btn {
    flex: 1 1 auto !important;
  }
}

/* ===== Fix mixed Arabic + email direction in settings line ===== */
#me-line { line-height: 1.6; }
#me-line .bdi-email {
  direction: ltr;
  unicode-bidi: plaintext;
  word-break: break-word;
}

/* ===== Mobile hamburger header (same in EN + AR) ===== */
.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Mobile behavior */
@media (max-width: 720px) {
  /* Brand + hamburger on one line */
  .header-inner {
    flex-wrap: nowrap !important;
  }

  .brand {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  /* Show hamburger */
  .menu-btn {
    display: inline-flex;
  }

  /* Hide controls by default on mobile */
  .controls {
    display: none !important;
  }

  /* Dropdown panel (opens when header has .nav-open) */
  .header.nav-open .controls {
    display: flex !important;
    position: absolute;
    left: 12px;
    right: 12px;
    top: calc(100% + 10px);
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    z-index: 60;
  }

  html[data-theme="dark"] .header.nav-open .controls,
  body[data-theme="dark"] .header.nav-open .controls {
    background: rgba(6, 11, 20, 0.88);
  }

  /* Make buttons full width inside menu */
  .header.nav-open .controls .icon-btn {
    width: 100%;
    justify-content: center;
  }
}
