/* =====================================================================
   SAMAD Calendar App — styles
   Optimized for an iPad in landscape mode sitting on a desk, but works
   on any screen down to a phone width too.
   ===================================================================== */

:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --text: #1c1f26;
  --text-dim: #6b7280;
  --border: #e3e5ea;
  --accent: #3b5bfd;
  --accent-dim: #eef1ff;
  --orange: #ff8a1e;
  --orange-bg: #fff2e2;
  --red: #e5484d;
  --red-bg: #fde8e8;
  --gray: #9aa0aa;
  --gray-bg: #eef0f2;
  --green: #17a34a;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b;
    --panel-bg: #1c1f26;
    --text: #f2f3f5;
    --text-dim: #9aa0aa;
    --border: #2b2f38;
    --accent: #6b85ff;
    --accent-dim: #232a4d;
    --orange-bg: #3a2712;
    --red-bg: #3a1a1b;
    --gray-bg: #262a31;
  }
}
:root[data-theme="dark"] {
  --bg: #14161b;
  --panel-bg: #1c1f26;
  --text: #f2f3f5;
  --text-dim: #9aa0aa;
  --border: #2b2f38;
  --accent: #6b85ff;
  --accent-dim: #232a4d;
  --orange-bg: #3a2712;
  --red-bg: #3a1a1b;
  --gray-bg: #262a31;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ---------------- Top control bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.btn {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-dim); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; }
.btn.danger { color: var(--red); border-color: var(--red-bg); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 13px; cursor: pointer; background: var(--panel-bg);
}
.user-chip .avatar {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}

/* ---------------- Main layout: calendar left, sidebar right ---------------- */
.main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  gap: 16px;
  padding: 16px;
}

.calendar-pane {
  flex: 1 1 68%;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
  overflow: hidden;
}

.calendar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.calendar-header h2 { margin: 0; font-size: 20px; flex: 1; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-dim); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.weekdays div {
  padding: 8px 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  min-height: 0;
}

.day-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  position: relative;
  min-height: 0;
  overflow: hidden;
  transition: background .12s ease;
}
.day-cell:hover { background: var(--accent-dim); }
.day-cell.outside { color: var(--text-dim); background: var(--bg); }
.day-cell.today { background: var(--accent-dim); }
.day-cell.today .day-num { background: var(--accent); color: #fff; }
.day-cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

.day-num {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 13px; font-weight: 700;
  margin-bottom: 4px;
}

.day-events { display: flex; flex-direction: column; gap: 2px; overflow: hidden; flex: 1; }
.event-chip {
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.event-chip.meeting { background: var(--orange-bg); color: var(--orange); }
.event-chip.bid { background: var(--red-bg); color: var(--red); }
.event-chip.other { background: var(--gray-bg); color: var(--text-dim); }
.day-more { font-size: 10px; color: var(--text-dim); margin-top: 1px; }

.day-dots { display: flex; gap: 3px; margin-top: auto; }
.day-dots .d { width: 6px; height: 6px; border-radius: 50%; }
.day-dots .d.meeting { background: var(--orange); }
.day-dots .d.bid { background: var(--red); }
.day-dots .d.other { background: var(--gray); }

/* ---------------- Right sidebar ---------------- */
.sidebar {
  flex: 1 1 32%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
}
.panel-header .count {
  font-size: 11px; color: var(--text-dim); font-weight: 600;
  background: var(--gray-bg); padding: 1px 7px; border-radius: 999px;
}
.panel-body { padding: 10px 14px; overflow-y: auto; flex: 1; min-height: 0; }
.panel.todo { flex: 1 1 55%; }
.panel.upcoming { flex: 1 1 45%; }

.todo-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.todo-item:last-child { border-bottom: none; }
.todo-item input[type="checkbox"] { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.todo-item.done .title { text-decoration: line-through; color: var(--text-dim); }
.todo-item .title { flex: 1; }
.todo-item .due { font-size: 11px; color: var(--text-dim); }
.todo-item .del { opacity: 0; cursor: pointer; color: var(--text-dim); font-size: 13px; }
.todo-item:hover .del { opacity: 1; }

.add-inline { display: flex; gap: 6px; padding-top: 8px; }
.add-inline input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px;
  font-size: 13px; background: var(--bg); color: var(--text);
}

.upcoming-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.upcoming-item:last-child { border-bottom: none; }
.upcoming-item .bar { width: 4px; align-self: stretch; border-radius: 3px; flex: 0 0 auto; }
.upcoming-item .bar.meeting { background: var(--orange); }
.upcoming-item .bar.bid { background: var(--red); }
.upcoming-item .bar.other { background: var(--gray); }
.upcoming-item .info { flex: 1; min-width: 0; }
.upcoming-item .t { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-item .d { font-size: 11.5px; color: var(--text-dim); }
.badge {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .03em;
}
.badge.meeting { background: var(--orange-bg); color: var(--orange); }
.badge.bid { background: var(--red-bg); color: var(--red); }
.badge.other { background: var(--gray-bg); color: var(--text-dim); }

.empty-hint { color: var(--text-dim); font-size: 13px; padding: 10px 2px; }

/* ---------------- Modal ---------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 17, 22, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal {
  background: var(--panel-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-dim); margin-bottom: 5px; }
.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field input[type="email"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 10px; font-size: 14px; background: var(--bg); color: var(--text);
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 60px; }
.type-picker { display: flex; gap: 8px; }
.type-picker label {
  flex: 1; border: 1px solid var(--border); border-radius: 9px; padding: 8px 6px;
  text-align: center; font-size: 12.5px; font-weight: 700; cursor: pointer; color: var(--text-dim);
}
.type-picker input { display: none; }
.type-picker input:checked + span { color: inherit; }
.type-picker label.meeting:has(input:checked) { background: var(--orange-bg); color: var(--orange); border-color: var(--orange); }
.type-picker label.bid:has(input:checked) { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.type-picker label.other:has(input:checked) { background: var(--gray-bg); color: var(--text-dim); border-color: var(--gray); }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.modal-actions .right { display: flex; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin-top: 6px; }

/* Admin panel */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.admin-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.admin-card h4 { margin: 0 0 4px; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.admin-card .big { font-size: 26px; font-weight: 800; }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.admin-table th, table.admin-table td {
  text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border);
}
table.admin-table th { color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--panel-bg);
  padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lg); z-index: 100; opacity: 0; transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.auth-gate {
  flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px;
}
.auth-card {
  background: var(--panel-bg); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 30px; width: 100%; max-width: 380px;
}
.auth-card h2 { margin-top: 0; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.auth-tabs button {
  flex: 1; padding: 8px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--panel-bg); color: var(--text-dim); font-weight: 700; font-size: 13px; cursor: pointer;
}
.auth-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--panel-bg);
  font-weight: 700; font-size: 14px; cursor: pointer; color: var(--text);
}

/* ---------------- Responsive (portrait tablet / phone) ---------------- */
@media (max-width: 860px) {
  .main { flex-direction: column; overflow-y: auto; }
  .calendar-pane { flex: 1 1 auto; }
  .sidebar { max-width: none; flex-direction: row; }
  .grid { min-height: 380px; }
}
@media (max-width: 560px) {
  .sidebar { flex-direction: column; }
  .topbar .brand span.label { display: none; }
}
