/* The hidden attribute must always win over element display rules,
   e.g. #login uses display:flex which would otherwise keep it visible. */
[hidden] { display: none !important; }

:root {
  --bg: #0d1117;
  --bg-elev: #121a26;
  --panel: #151d2b;
  --panel-2: #1a2434;
  --border: #27334a;
  --text: #e6ebf2;
  --muted: #8ea0b6;
  --accent: #3d8bfd;
  --accent-hi: #6aa8ff;
  --danger: #e5534b;
  --success: #3fb950;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 12px 34px rgba(0, 0, 0, .4);
  --focus: 0 0 0 3px rgba(61, 139, 253, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1100px 550px at 75% -10%, #14233b 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; }

button {
  padding: .45rem .9rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}

button:hover { background: var(--border); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button:focus-visible, input:focus-visible { outline: none; box-shadow: var(--focus); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover { background: var(--accent-hi); }

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

button.danger:hover { filter: brightness(1.1); }

.screen { max-width: 960px; margin: 0 auto; padding: 1.2rem; }

/* ---------- login ---------- */

#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#login-form {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.2rem;
}

#login-form h1 { margin: 0 0 .25rem; font-size: 1.5rem; letter-spacing: .3px; }
#login-form .tagline { margin: 0 0 1.6rem; color: var(--muted); font-size: .9rem; }

label { display: block; margin-bottom: 1.1rem; color: var(--muted); font-size: .85rem; font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"] {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .55rem .7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}

input[type="text"]:focus-visible, input[type="email"]:focus-visible, input[type="password"]:focus-visible { border-color: var(--accent); }

.error { color: var(--danger); font-size: .85rem; margin: 0 0 .9rem; }

#login-form button { width: 100%; margin-top: .4rem; }

/* ---------- setup / register ---------- */

#setup, #register {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#setup-form, #register-form {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.2rem;
}

#setup-form h1, #register-form h1 { margin: 0 0 .25rem; font-size: 1.5rem; letter-spacing: .3px; }
#setup-form .tagline, #register-form .tagline { margin: 0 0 1.6rem; color: var(--muted); font-size: .9rem; }
#setup-form button, #register-form button { width: 100%; margin-top: .4rem; }

/* ---------- recovery phrase ---------- */

#phrase {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.phrase-card {
  width: 100%;
  max-width: 500px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.2rem;
}

.phrase-card h1 { margin: 0 0 .25rem; font-size: 1.5rem; letter-spacing: .3px; }
.phrase-card .tagline { margin: 0 0 1.4rem; color: var(--muted); font-size: .9rem; }

.phrase-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.7;
  padding: 1rem;
  margin: 0 0 1.2rem;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  user-select: all;
  word-break: break-word;
}

.phrase-actions { display: flex; gap: .6rem; }
.phrase-actions button { flex: 1; }

/* ---------- vault view ---------- */

#vault-wrap { min-height: 260px; }

.vault-card {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.2rem;
  margin: 2rem auto;
}

.vault-card h2 { margin: 0 0 .25rem; font-size: 1.25rem; }
.vault-card .tagline { margin: 0 0 1.4rem; color: var(--muted); font-size: .9rem; }
.vault-card button { margin-top: .4rem; }

#vault-toolbar { justify-content: flex-start; gap: .5rem; }
#vault-trash-toolbar { justify-content: flex-start; gap: .5rem; }
#vault-trash-info { margin-right: auto; color: var(--muted); font-size: .85rem; }

.vault-card-link {
  margin-top: 1rem;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
}

.vault-card-link svg { width: 15px; height: 15px; }

/* ---------- settings view ---------- */

.settings-wrap { max-width: 640px; }

.settings-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.2rem;
}

.settings-card h3 { margin: 0 0 .25rem; font-size: 1.1rem; }
.settings-card .tagline { margin: 0 0 1.1rem; color: var(--muted); font-size: .9rem; }
.settings-card form label { display: block; margin-bottom: .8rem; }
.settings-card input { width: 100%; }

/* ---------- users view ---------- */

.users-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .6rem;
  padding: .9rem;
  border-bottom: 1px solid var(--border);
}

.users-title h2 { margin: 0; font-size: 1.05rem; }
.users-title p { margin: .15rem 0 0; color: var(--muted); font-size: .82rem; }
.users-sub { padding: 1.1rem .9rem .4rem; }

tbody tr.self td.name .fname::after { content: " (you)"; color: var(--muted); font-size: .78rem; }

#invites td.name .invite-link, td.invite-link { cursor: pointer; }
td.invite-link .fname { color: var(--accent); max-width: 300px; }
td.invite-link:hover .fname { text-decoration: underline; }

.invite-link-input {
  width: 100%;
  margin-bottom: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
}

/* ---------- app chrome ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .9rem;
  padding: .8rem 1.2rem;
  margin: -1.2rem -1.2rem 0;
  background: rgba(13, 17, 23, .85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .3px;
  white-space: nowrap;
}

.brand::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  margin-right: .5rem;
  vertical-align: 1px;
}

.crumb-bar {
  display: flex;
  align-items: center;
  gap: .2rem;
  color: var(--muted);
  font-size: .9rem;
  min-width: 0;
  overflow: hidden;
  padding: .45rem 1.2rem;
  margin: 0 -1.2rem 1.1rem;
  background: rgba(13, 17, 23, .5);
  border-bottom: 1px solid var(--border);
}

#breadcrumb .crumb {
  background: none;
  border: none;
  color: var(--accent);
  padding: .2rem .3rem;
  white-space: nowrap;
}

#breadcrumb .crumb:hover { background: none; text-decoration: underline; }
#breadcrumb .sep { color: var(--border); margin: 0 .1rem; }

#breadcrumb .here {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.spacer { flex: 1; }

#whoami { color: var(--muted); font-size: .85rem; white-space: nowrap; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  white-space: nowrap;
}

.nav-btn svg { width: 15px; height: 15px; }

.nav-btn.active {
  color: var(--accent-hi);
  border-color: var(--accent);
  background: var(--panel);
}

/* ---------- toolbar ---------- */

.toolbar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }

.toolbar button, .cal-toolbar button, .trash-toolbar button, .users-toolbar button, #vault-toolbar button {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}

.toolbar button svg, .cal-toolbar button svg, .trash-toolbar button svg, .users-toolbar button svg,
#vault-toolbar button svg, .icon-btn svg, td.name .icon svg { width: 15px; height: 15px; }

.toolbar button.primary svg, .cal-toolbar button.primary svg, .trash-toolbar button.primary svg,
.users-toolbar button.primary svg, #vault-toolbar button.primary svg { color: #fff; }

/* ---------- transfer status ---------- */

.transfer-status {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin: 0 0 1rem;
  padding: .6rem .9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.transfer-status progress {
  flex: 1;
  height: 8px;
  appearance: none;
  border: none;
  border-radius: 4px;
  background: var(--border);
}

progress::-webkit-progress-bar { background: var(--border); border-radius: 4px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 4px; }

#upload-label, #download-label {
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

/* ---------- quota bar ---------- */

.quota-bar {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin: 0 0 1rem;
  padding: .45rem .9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.quota-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}

.quota-fill.full {
  background: var(--danger);
}

.quota-label {
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
}

/* ---------- file table ---------- */

.table-wrap {
  position: relative;
  min-height: 130px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-wrap.loading { pointer-events: none; }

.table-wrap.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, .4);
  z-index: 1;
}

.table-wrap.loading::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -16px 0 0 -16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  z-index: 2;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

table { width: 100%; border-collapse: collapse; min-width: 560px; }

th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }

th {
  color: var(--muted);
  font-weight: 600;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--bg-elev); }

td.name { cursor: pointer; }
td.name .icon { display: inline-block; margin-right: .5rem; vertical-align: -3px; color: var(--muted); }
td.name .icon.folder { color: var(--accent); }
td.name .fname {
  display: inline-block;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

td.size, th:nth-child(2) { width: 90px; text-align: right; }
td.mtime, th:nth-child(3) { width: 170px; color: var(--muted); }
th.actions-col, td.actions { width: 110px; text-align: right; }

td.actions { white-space: nowrap; }

td.actions .icon-btn {
  background: none;
  border: none;
  padding: .32rem .45rem;
  margin: 0 .05rem;
  border-radius: 6px;
  color: var(--muted);
  opacity: .35;
}

tbody tr:hover td.actions .icon-btn,
td.actions .icon-btn:focus-visible { opacity: 1; }

td.actions .icon-btn:hover { background: var(--panel-2); color: var(--accent); }
td.actions .icon-btn.danger:hover { color: var(--danger); }

@media (hover: none) {
  td.actions .icon-btn { opacity: 1; }
}

/* ---------- trash view ---------- */

.trash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border);
}

#trash-info { color: var(--muted); font-size: .85rem; }

td.name .orig {
  display: block;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .74rem;
}

tbody tr.missing { opacity: .55; }

tbody tr.missing td.name .orig { color: var(--danger); }

/* ---------- empty state ---------- */

.empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }

.empty .msg { display: block; margin-bottom: .9rem; }

.empty .em { display: block; margin-bottom: .8rem; }
.empty .em svg { width: 48px; height: 48px; color: var(--border); }

/* ---------- gallery ---------- */

.gallery-wrap {
  position: relative;
  min-height: 130px;
}

.gallery-wrap.loading { pointer-events: none; }

.gallery-wrap.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 23, .4);
  z-index: 1;
}

.gallery-wrap.loading::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -16px 0 0 -16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  z-index: 2;
  animation: spin .7s linear infinite;
}

#gallery-info {
  margin: 0 0 .7rem;
  color: var(--muted);
  font-size: .85rem;
  min-height: 1.2em;
}

.media-group { margin-bottom: 1.4rem; }

.media-group .month {
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .6rem;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  overflow: hidden;
  cursor: pointer;
}

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

.tile .thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  background: var(--panel-2);
  overflow: hidden;
}

.tile.loading .thumb::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 60%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .07), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.1s infinite;
}

@keyframes shimmer { to { transform: translateX(270%); } }

.tile .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile .thumb .ph { width: 30px; height: 30px; color: var(--muted); }
.tile .thumb .ph svg { width: 30px; height: 30px; }

.tile.folder .thumb .ph { color: var(--accent); }

.tile .play-badge {
  position: absolute;
  right: .45rem;
  bottom: .45rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile .play-badge svg { width: 14px; height: 14px; margin-left: 2px; }

.tile .cap {
  padding: .4rem .55rem;
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--border);
}

.tile.failed .thumb { color: var(--muted); }

.spinner {
  width: 26px;
  height: 26px;
  margin: 2.5rem auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ---------- photos sidebar ---------- */

#gallery-wrap.photos {
  display: flex;
  gap: 1.2rem;
  align-items: flex-start;
}

.photos-side {
  flex: 0 0 215px;
  position: sticky;
  top: .5rem;
}

.side-section { margin-bottom: 1.4rem; }

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .4rem;
}

.side-title h3 {
  margin: 0;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.side-add {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.side-add:hover { border-color: var(--accent); color: var(--accent); }

.side-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 42vh;
  overflow-y: auto;
}

.side-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .38rem .5rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  text-align: left;
  font-size: .85rem;
  cursor: pointer;
}

.side-item:hover { background: var(--panel-2); }

.side-item.active {
  border-color: var(--accent);
  background: rgba(61, 139, 253, .12);
}

.side-item .cnt {
  margin-left: auto;
  color: var(--muted);
  font-size: .75rem;
}

.side-item .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.side-row .side-item { flex: 1; min-width: 0; }

.side-action {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  opacity: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.side-row:hover .side-action { opacity: 1; }
.side-action:hover { color: var(--accent); background: var(--panel-2); }
.side-action svg { width: 13px; height: 13px; }

.side-item.empty { color: var(--muted); font-style: italic; cursor: default; }
.side-item.empty:hover { background: none; }

.photos-main { flex: 1; min-width: 0; }

.photos-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

#gallery-wrap.photos #gallery-info { margin-bottom: .7rem; }

.photos-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap;
}

.photos-actions button {
  padding: .28rem .6rem;
  font-size: .8rem;
}

.selection-count {
  color: var(--muted);
  font-size: .8rem;
}

.tile.selectable .tick {
  position: absolute;
  top: .45rem;
  left: .45rem;
  z-index: 2;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 50%;
  background: rgba(0, 0, 0, .4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile.selectable .tick svg { width: 14px; height: 14px; }

.tile.selectable.selected .tick {
  background: var(--accent);
  border-color: var(--accent);
}

.tile.selectable.selected { border-color: var(--accent); }

/* ---------- lightbox ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, .93);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.lb-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1rem;
}

.lb-count { color: var(--muted); font-size: .85rem; }

.lb-buttons { display: flex; gap: .25rem; }

.lb-icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: none;
  border: none;
  color: #fff;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lb-icon-btn svg { width: 20px; height: 20px; }
.lb-icon-btn:hover { background: rgba(255, 255, 255, .15); }

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .18);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-nav svg { width: 22px; height: 22px; }
.lb-nav:hover { background: rgba(255, 255, 255, .2); }

#lb-prev { left: 1rem; }
#lb-next { right: 1rem; }

.lb-stage {
  position: relative;
  max-width: calc(100vw - 7rem);
  max-height: calc(100vh - 8rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

#lb-img {
  max-width: calc(100vw - 7rem);
  max-height: calc(100vh - 8rem);
  border-radius: 4px;
  object-fit: contain;
}

#lb-video {
  max-width: calc(100vw - 7rem);
  max-height: calc(100vh - 8rem);
  background: #000;
  border-radius: 4px;
}

.lb-loading { color: var(--muted); font-size: .95rem; }

.lb-cap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .8rem 1.2rem 1rem;
  text-align: center;
  font-size: .9rem;
}

.lb-cap small { color: var(--muted); margin-left: .6rem; }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .4rem; }
  .lb-nav { width: 38px; height: 38px; }
  #lb-prev { left: .4rem; }
  #lb-next { right: .4rem; }
}

/* ---------- modal dialog ---------- */

dialog#modal {
  border: none;
  padding: 0;
  margin: auto;
  width: min(440px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  background: transparent;
  color: var(--text);
}

dialog#modal::backdrop { background: rgba(0, 0, 0, .55); }

dialog#modal[open] { animation: pop .15s ease; }

@keyframes pop {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: none; }
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.4rem;
}

.modal-card h2 { margin: 0 0 .3rem; font-size: 1.15rem; }

.modal-card .modal-msg { margin: 0 0 1rem; color: var(--muted); font-size: .92rem; }

.modal-body { margin-bottom: .4rem; }

.modal-body label:last-child { margin-bottom: 0; }

.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 360px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: .7rem .9rem;
  box-shadow: var(--shadow);
  animation: slide-in .18s ease;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

.toast .msg { flex: 1; font-size: .9rem; }

.toast .close {
  background: none;
  border: none;
  padding: .1rem .3rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}

.toast .close:hover { background: none; color: var(--text); }

.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }

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

/* ---------- calendar ---------- */

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.cal-title { margin: 0; font-size: 1.05rem; min-width: 150px; }

.cal-nav { padding: .4rem .55rem; line-height: 1; }

.cal-views {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.cal-view-btn {
  background: var(--panel-2);
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: .4rem .7rem;
  font-size: .84rem;
}

.cal-view-btn:last-child { border-right: none; }
.cal-view-btn:hover { background: var(--border); }
.cal-view-btn.active { background: var(--accent); color: #fff; }

.cal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.cal-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .22rem .7rem;
  font-size: .82rem;
}

.cal-chip:hover { border-color: var(--accent); }
.cal-chip.active { border-color: var(--accent); color: var(--accent-hi); background: rgba(61, 139, 253, .1); }
.cal-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }

.cal-grid { padding: .3rem; }

.cal-grid.month { display: grid; grid-template-columns: 2.6rem repeat(7, 1fr); gap: 2px; }

.cal-row { display: contents; }

.cal-cell {
  min-height: 96px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .2rem .3rem;
  overflow: hidden;
}

.cal-cell.off { background: rgba(13, 17, 23, .45); }
.cal-cell.today { border-color: var(--accent); }

.cal-head-cell {
  min-height: 0;
  background: none;
  border: none;
  text-align: center;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: .3rem 0;
}

.cal-weeknum-head {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  text-align: center;
  padding: .3rem 0;
}

.cal-weeknum {
  background: rgba(13, 17, 23, .35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
}

.cal-weeknum-gutter {
  display: block;
  text-align: center;
  font-size: .68rem;
  color: var(--muted);
  padding-top: .5rem;
}

.cal-daynum { font-size: .78rem; font-weight: 600; color: var(--muted); padding: .1rem .2rem; }
.cal-cell.today .cal-daynum { color: var(--accent-hi); }

.cal-events { display: flex; flex-direction: column; gap: 2px; }

.cal-pill {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: .15rem .35rem;
  text-align: left;
  font-size: .75rem;
  line-height: 1.25;
  color: var(--text);
  overflow: hidden;
  cursor: pointer;
}

.cal-pill:hover { filter: brightness(1.18); }

.cal-pill.month { display: block; white-space: nowrap; text-overflow: ellipsis; }

.cal-pill.task { border-left-style: dashed; }
.cal-pill.task .cal-sum::before { content: "\2610 "; color: var(--muted); }

.cal-pill .cal-t { color: var(--muted); font-size: .7rem; }
.cal-pill .cal-sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cal-more { color: var(--muted); font-size: .72rem; padding: .1rem .3rem; cursor: pointer; }
.cal-more:hover { color: var(--accent-hi); }

.cal-grid.time { padding: 0; }

.cal-time-head {
  display: flex;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

.cal-gutter { flex: 0 0 52px; }

.cal-dayhead {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: .5rem 0;
  border-left: 1px solid var(--border);
}

.cal-dayhead.today .cal-dn { color: var(--accent-hi); }
.cal-wd { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.cal-dn { font-size: 1rem; font-weight: 700; }
.cal-month { font-size: .78rem; color: var(--muted); }

.cal-time-body { display: flex; }

.cal-hours { flex: 0 0 52px; }

.cal-hour { position: relative; border-bottom: 1px solid rgba(39, 51, 74, .4); }

.cal-hourlabel {
  position: absolute;
  top: -7px;
  right: 6px;
  font-size: .68rem;
  color: var(--muted);
  background: var(--panel);
  padding: 0 2px;
}

.cal-days { flex: 1; display: flex; }

.cal-daycol {
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--border);
}

.cal-allday {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px;
  border-bottom: 1px solid var(--border);
  min-height: 8px;
}

.cal-allday:empty { display: none; }

.cal-timed {
  position: relative;
  background: repeating-linear-gradient(to bottom,
    transparent 0,
    transparent calc(44px - 1px),
    rgba(39, 51, 74, .35) calc(44px - 1px),
    rgba(39, 51, 74, .35) 44px);
}

.cal-daycol.today .cal-timed { background-color: rgba(61, 139, 253, .04); }

.cal-pill.time { position: absolute; left: 2px; right: 2px; min-height: 22px; }
.cal-pill.time.allday { position: relative; left: auto; right: auto; top: auto; height: auto; }

/* tasks panel */

.tasks-panel {
  border-top: 1px solid var(--border);
  padding: .6rem 1rem 1rem;
}

.tasks-title h3 {
  margin: 0 0 .5rem;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.tasks-list { display: flex; flex-direction: column; gap: 2px; max-width: 720px; }

.task {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.task:hover { background: var(--panel-2); }

.task.done .task-sum { text-decoration: line-through; color: var(--muted); }

.task-toggle {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.task-toggle svg { width: 13px; height: 13px; }

.task-toggle.checked { color: #fff; background: var(--success); border-color: var(--success); }

.task-main {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: .6rem;
  min-width: 0;
  background: none;
  border: none;
  padding: .2rem .2rem;
  text-align: left;
  color: var(--text);
}

.task-main:hover { background: none; }

.task-sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-due { color: var(--muted); font-size: .78rem; white-space: nowrap; }

.task-group {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: .6rem 0 .2rem;
}

.cal-empty { color: var(--muted); font-size: .88rem; margin: .4rem 0; }

/* ---------- contacts ---------- */

.contacts-wrap { display: flex; gap: 1.2rem; padding: 1.2rem; align-items: flex-start; }

.contacts-side {
  flex: 0 0 215px;
  position: sticky;
  top: .5rem;
}

.contacts-main { flex: 1; min-width: 0; }

.contacts-top {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .9rem;
  position: relative;
}

.search-icon { position: absolute; left: .7rem; color: var(--muted); width: 15px; height: 15px; pointer-events: none; }

.contacts-top #contact-search {
  flex: 1;
  max-width: 340px;
  margin: 0;
  padding-left: 2.1rem;
}

.contacts-info { color: var(--muted); font-size: .85rem; margin: 0 auto 0 0; }

.contact-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .5rem; }

.contact {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .7rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--text);
  min-width: 0;
}

.contact:hover { border-color: var(--accent); }

.avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 600;
}

.contact-main { display: flex; flex-direction: column; min-width: 0; }

.contact-name { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-sub { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* modal extras */

.modal-body input[type="date"],
.modal-body input[type="time"],
.modal-body input[type="datetime-local"],
.modal-body select,
.modal-body textarea {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .55rem .7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}

.modal-body input:focus-visible,
.modal-body select:focus-visible,
.modal-body textarea:focus-visible { border-color: var(--accent); }

.modal-body input[type="color"] {
  width: 100%;
  height: 38px;
  margin-top: .35rem;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal-body textarea { resize: vertical; }

.check-field {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .9rem;
  color: var(--text);
}

.modal-note { color: var(--muted); font-size: .8rem; margin: .2rem 0 .8rem; }

.rows-field { margin-bottom: 1rem; }

.rows-label {
  display: block;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: .3rem;
}

.rows { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .4rem; }

.row { display: flex; gap: .4rem; }

.row input { margin-top: 0; }

.row-del {
  flex: 0 0 auto;
  width: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.row-del svg { width: 14px; height: 14px; }
.row-del:hover { color: var(--danger); }

.row-add { background: none; border: 1px dashed var(--border); color: var(--accent-hi); font-size: .84rem; }
.row-add:hover { background: var(--panel-2); }

.attendee-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
}
.attendee-row input[type="text"] { flex: 1 1 110px; }
.attendee-row input[type="email"] { flex: 1 1 160px; }
.attendee-row input[type="text"],
.attendee-row input[type="email"] { margin-top: 0; }
.attendee-row select { margin-top: 0; width: auto; }
.attendee-rsvp {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}
.attendee-rsvp input { margin: 0; }

.manager-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .4rem;
  border-bottom: 1px solid var(--border);
}

.manager-row:last-child { border-bottom: none; }

.manager-name { flex: 1; min-width: 0; font-size: .92rem; overflow-wrap: anywhere; }

.manager-meta { display: inline-block; color: var(--muted); font-size: .75rem; }

.manager-row .icon-btn { background: none; border: none; color: var(--muted); padding: .3rem .4rem; border-radius: 6px; }
.manager-row .icon-btn:hover { background: var(--panel-2); color: var(--accent); }
.manager-row .icon-btn.danger:hover { color: var(--danger); }
.manager-row .icon-btn svg { width: 15px; height: 15px; }

@media (max-width: 760px) {
  .contacts-wrap { flex-direction: column; }
  .contacts-side { position: static; width: 100%; flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
