:root {
  --brand: #1b6ec2;
  --brand-dark: #14528f;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #dde3ea;
  --text: #1f2933;
  --muted: #6b7785;
  --danger: #c0392b;
  --success: #1e8e3e;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.topbar .brand { font-weight: 700; font-size: 17px; color: var(--text); }
.topbar nav a {
  color: var(--text);
  margin-left: 18px;
  font-size: 14px;
  font-weight: 500;
}
.topbar nav a.active { color: var(--brand); }
.topbar .who { color: var(--muted); font-size: 13px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.container.narrow { max-width: 480px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f0f2f5; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }

form .field { margin-bottom: 14px; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.flash.success { background: #e6f4ea; color: var(--success); }
.flash.error { background: #fbeae8; color: var(--danger); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a {
  padding: 9px 14px;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}
.tabs a.active {
  color: var(--brand);
  background: var(--card);
  border-color: var(--border);
  border-bottom-color: var(--card);
  margin-bottom: -1px;
}

/* Second-row sub-tab strip (e.g. Roses -> White, Red) — smaller and set
   apart from the top-level group tabs above it. */
.tabs.subtabs {
  margin-top: -18px;
  margin-bottom: 18px;
  padding-left: 6px;
  border-bottom-color: var(--border);
}
.tabs.subtabs a {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
}

.resource-list { display: grid; gap: 12px; }
.resource-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.resource-item .title { font-weight: 700; margin-bottom: 4px; }
.resource-item .snippet { color: var(--muted); font-size: 13px; }
.resource-item .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.resource-item .actions { display: flex; gap: 8px; flex-shrink: 0; }

.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin-top: 10px; }
.file-thumb { border: 1px solid var(--border); border-radius: 6px; padding: 6px; text-align: center; background: #fafbfc; position: relative; }
.file-thumb img { max-width: 100%; height: 80px; object-fit: cover; border-radius: 4px; cursor: zoom-in; }
.file-thumb .fname { font-size: 11px; margin-top: 4px; word-break: break-word; color: var(--text); }
.file-thumb .ficon { font-size: 32px; height: 80px; display: flex; align-items: center; justify-content: center; }
.thumb-media { position: relative; }
.thumb-media label { position: absolute; top: 4px; left: 4px; margin: 0; }
.file-thumb .fname-top {
  width: 100%; font-size: 12px; font-weight: 700; padding: 4px 6px;
  margin-bottom: 6px; border: 1px solid transparent; background: transparent;
  text-align: center;
}
.file-thumb .fname-top:hover, .file-thumb .fname-top:focus { border-color: var(--border); background: #fff; }
.file-thumb .meta-edit { margin-top: 4px; text-align: left; }
.file-thumb .meta-edit summary {
  font-size: 10.5px; color: var(--brand); cursor: pointer; font-weight: 600;
  padding: 2px 0;
}

/* Thumbnail size preference (S/M/L toggle). No extra class = current
   default size at every breakpoint, unchanged. These override at every
   breakpoint because two classes beat the single .file-grid selector
   used in the responsive rules below. */
.file-grid.size-sm { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.file-grid.size-sm .file-thumb img, .file-grid.size-sm .file-thumb .ficon { height: 54px; }
.file-grid.size-lg { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.file-grid.size-lg .file-thumb img, .file-grid.size-lg .file-thumb .ficon { height: 130px; }

.size-toggle { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.size-toggle span { color: var(--muted); font-size: 12px; }
.size-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 10px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--text);
}
.size-btn:hover { background: #f0f2f5; }
.size-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Selected-attachments summary (Compose & Send) — small thumbnail + name
   for each picked file, so you can see at a glance what's attached
   without scrolling back to the grid. */
.selected-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.selected-chips:not(.has-items) { color: var(--muted); font-size: 12px; }
.selected-chips .chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef4fb; border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 10px 3px 3px; font-size: 12px; font-weight: 600; color: var(--text);
}
.selected-chips .chip img {
  width: 24px; height: 24px; object-fit: cover; border-radius: 50%; flex-shrink: 0;
}
.selected-chips .chip .ficon-sm { font-size: 14px; }
.selected-chips .chip .chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.badge.sent { background: #e6f4ea; color: var(--success); }
.badge.failed { background: #fbeae8; color: var(--danger); }

.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

/* ---- Photo lightbox (name + close, image below) ---- */
.lightbox-backdrop {
  position: fixed; inset: 0; background: rgba(20, 24, 28, .65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 1000;
}
.lightbox {
  background: var(--card);
  border-radius: 12px;
  max-width: 640px; width: 100%; max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.lightbox-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.lightbox-header h3 { margin: 0; font-size: 19px; line-height: 1.3; }
.lightbox-close {
  background: none; border: none; font-size: 24px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 4px; flex-shrink: 0;
}
.lightbox-close:hover { color: var(--text); }
.lightbox-body { padding: 18px 20px; overflow: auto; text-align: center; background: #fafbfc; }
.lightbox-body img { max-width: 100%; max-height: 68vh; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---- Rich text editor (used for canned response / standard text) ---- */
.rte-wrapper { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; background: #f4f6f8; border-bottom: 1px solid var(--border); }
.rte-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 4px;
  padding: 5px 9px; font-size: 12px; cursor: pointer; color: var(--text);
  min-width: 30px;
}
.rte-btn:hover { background: #eef1f4; }
.rte-sep { width: 1px; background: var(--border); margin: 2px 4px; }
.rte-editor {
  min-height: 160px; max-height: 420px; overflow-y: auto;
  padding: 12px 14px; font-size: 14px; line-height: 1.5; outline: none;
}
.rte-editor ul, .rte-editor ol { padding-left: 22px; margin: 8px 0; }
.rte-editor p { margin: 0 0 10px; }
.rte-editor a { color: var(--brand); }
.rte-editor:empty:before { content: attr(data-placeholder); color: var(--muted); }

/* ---- Responsive: tablet (iPad) ---- */
@media (max-width: 900px) {
  .container { padding: 18px 14px 50px; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* ---- Responsive: phone ---- */
@media (max-width: 640px) {
  body { font-size: 16px; } /* avoid iOS auto-zoom on inputs */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 8px 0;
  }
  .topbar .brand { width: 100%; }
  .topbar nav {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
  }
  .topbar nav a { margin-left: 0; }
  .topbar .who { width: 100%; order: 99; padding-top: 4px; border-top: 1px solid var(--border); margin-top: 4px; }

  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .tabs a { flex-shrink: 0; }

  .resource-item { flex-direction: column; }
  .resource-item .actions { width: 100%; }
  .resource-item .actions .btn { flex: 1; text-align: center; }

  .two-col { gap: 14px; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
  .file-thumb img, .file-thumb .ficon { height: 64px; }

  table { display: block; }
  .card > table, .card table { min-width: 560px; }
  .card:has(table) { overflow-x: auto; }
}
