/* Mobile-first. Layout uses logical properties (inline-start/end) so the RTL
   mirror is real, not a text-direction flip. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #16202e;
  --text-muted: #5c6b7f;
  --border: #d8dfe8;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e2f0ea;
  --shared: #2f6f5e;
  --personal: #4a6fa5;
  --pending: #b07d2b;
  --danger: #b3392f;
  --radius: 14px;
  --tap: 46px;
  --shadow: 0 1px 3px rgba(20, 32, 46, .09), 0 6px 18px rgba(20, 32, 46, .06);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #12171f;
  --surface: #1a212c;
  --surface-2: #222b38;
  --text: #e8edf4;
  --text-muted: #9aa8ba;
  --border: #2f3a49;
  --accent: #4fae91;
  --accent-text: #0c1319;
  --accent-soft: #1e3730;
  --shared: #4fae91;
  --personal: #7ba1d8;
  --pending: #d8a94e;
  --danger: #e0685c;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

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

/* ---------- App shell ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-block-end: 1px solid var(--border);
}

.app-header h1 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

main { padding: 14px; padding-bottom: 96px; max-width: 900px; margin: 0 auto; }

/* ---------- Login ---------- */
.login-wrap {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    var(--bg);
}

/* Soft drifting colour fields behind the card. Purely decorative and cheap:
   three blurred blobs, no images, no library. */
.login-aurora { position: absolute; inset: 0; pointer-events: none; }
.login-aurora span {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(58px);
  opacity: .5;
}
.login-aurora span:nth-child(1) {
  width: 320px; height: 320px;
  inset-block-start: -70px; inset-inline-start: -60px;
  background: var(--accent);
  animation: drift-a 17s ease-in-out infinite alternate;
}
.login-aurora span:nth-child(2) {
  width: 260px; height: 260px;
  inset-block-end: -60px; inset-inline-end: -50px;
  background: var(--personal);
  animation: drift-b 21s ease-in-out infinite alternate;
}
.login-aurora span:nth-child(3) {
  width: 200px; height: 200px;
  inset-block-end: 24%; inset-inline-start: 28%;
  background: var(--pending);
  opacity: .28;
  animation: drift-c 25s ease-in-out infinite alternate;
}
@keyframes drift-a { to { transform: translate3d(26px, 34px, 0) scale(1.12); } }
@keyframes drift-b { to { transform: translate3d(-30px, -22px, 0) scale(1.08); } }
@keyframes drift-c { to { transform: translate3d(18px, -26px, 0) scale(1.15); } }

@media (prefers-reduced-motion: reduce) {
  .login-aurora span { animation: none; }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 390px;
  padding: 30px 24px 26px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  box-shadow: 0 18px 50px -12px rgba(12, 22, 34, .3), 0 2px 8px rgba(12, 22, 34, .08);
  animation: card-in .5s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .login-card { animation: none; }
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 19px;
  color: var(--accent-text);
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 62%, var(--personal)));
  box-shadow: 0 8px 22px -6px color-mix(in srgb, var(--accent) 62%, transparent);
}
.brand h1 {
  margin: 0;
  font-size: 1.42rem;
  font-weight: 700;
  letter-spacing: -.01em;
  text-align: center;
}

.login-card .field label { font-size: .8rem; }
.login-card .field input {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-card .field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.login-card .btn {
  margin-top: 6px;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 75%, transparent);
  transition: transform .12s ease, filter .15s ease;
}
.login-card .btn:hover:not(:disabled) { filter: brightness(1.06); }
.login-card .btn:active:not(:disabled) { transform: translateY(1px); }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 12px;
  font-weight: 650;
  cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: .88rem;
}

/* ---------- Calendar ---------- */
.cal-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}
.cal-bar .month-label {
  flex: 1;
  font-weight: 650;
  font-size: 1.05rem;
  text-align: center;
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  min-height: 38px;
  padding: 0 14px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.grid-head, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.grid-head { margin-bottom: 4px; }
.grid-head span {
  text-align: center;
  font-size: .72rem;
  font-weight: 650;
  color: var(--text-muted);
  padding: 4px 0;
}

.day-cell {
  position: relative;
  min-height: 62px;
  padding: 5px 4px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  text-align: start;
}
.day-cell.outside { opacity: .42; }
.day-cell.today { border-color: var(--accent); }
.day-cell[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.day-num { font-size: .82rem; font-weight: 600; }
.dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--personal); }
.dot.shared { background: var(--shared); }
.dot.pending { background: var(--pending); }

/* Week view: one column per day on wide screens, stacked rows on a phone. */
.week-list { display: grid; gap: 8px; }
.week-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.week-day.today { border-color: var(--accent); }
.week-day h3 { margin: 0 0 6px; font-size: .9rem; }

.day-panel { margin-top: 16px; }
.day-panel h2 { margin: 0 0 10px; font-size: 1rem; }

.event-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--personal);
  border-radius: var(--radius);
  text-align: start;
  cursor: pointer;
}
.event-item.shared { border-inline-start-color: var(--shared); }
.event-item.pending {
  border-style: dashed;
  border-inline-start-color: var(--pending);
  background: transparent;
}
.event-time {
  min-width: 58px;
  font-size: .8rem;
  font-weight: 650;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.event-body { flex: 1; min-width: 0; }
.event-title { font-weight: 600; overflow-wrap: anywhere; }
.event-meta { font-size: .78rem; color: var(--text-muted); }

.empty {
  padding: 26px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

.fab {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-end: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.7rem;
  line-height: 1;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 30;
}

/* ---------- Sheet / modal ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 24, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px 24px;
}
.sheet h2 { margin: 0 0 14px; font-size: 1.1rem; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn { width: auto; flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 21px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.settings-card h2 { margin: 0 0 12px; font-size: 1rem; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: .9rem; }
.kv span:first-child { color: var(--text-muted); }

.toast {
  position: fixed;
  inset-block-end: 90px;
  inset-inline: 0;
  margin-inline: auto;
  width: fit-content;
  max-width: 90%;
  padding: 10px 18px;
  border-radius: 22px;
  background: var(--text);
  color: var(--bg);
  font-size: .88rem;
  z-index: 50;
}

@media (min-width: 700px) {
  .day-cell { min-height: 86px; }
  .week-list { grid-template-columns: repeat(7, 1fr); }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}
