@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --navy: #101d33;
  --navy-light: #17284a;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --border: #e1e5eb;
  --text: #1c2534;
  --muted: #647087;
  --primary: #1d4ed8;
  --primary-dark: #1740b0;
  --danger: #c0362c;
  --unread-bg: #eef3fd;
  --radius: 8px;
}

* { box-sizing: border-box; }

.icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -4px; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; color: var(--text); }

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

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy);
  background-image: linear-gradient(135deg, var(--navy) 0%, #0a1424 100%);
}
.auth-form-panel { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: 0 20px 50px rgba(8, 15, 30, 0.35);
}
.auth-card h1 { margin-top: 0; }
.app-subtitle { color: var(--muted); margin-bottom: 20px; }

.auth-card label, form label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.auth-card input, form input[type=text], form input[type=email], form input[type=password], form input[type=number], form select, form textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
input::placeholder, textarea::placeholder { color: #9aa5b5; }
form details { margin: 4px 0 20px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 14px; }
form details[open] { padding-bottom: 14px; }
form details summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 13px; color: var(--muted); }
form details h3 { margin-top: 12px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.auth-card input:focus, form input:focus, form select:focus, form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15); }
.auth-card h3 { margin: 18px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.auth-switch { color: var(--muted); font-size: 14px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.flash-error { background: #fdeceb; color: #9a2c23; border: 1px solid #f3c6c1; }
.image-block-notice { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }

.save-btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
}
.save-btn:hover { background: var(--primary-dark); text-decoration: none; }
.draft-status { margin-left: 10px; font-size: 13px; color: var(--muted); }
.save-btn.danger { background: var(--danger); }
.save-btn.danger:hover { background: #9c2c24; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--navy);
  border-bottom: 1px solid #0a1424;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; letter-spacing: -0.01em; white-space: nowrap; }
.topbar-brand .icon { color: #8fa6d6; }

.topbar-search {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 14px;
}
.topbar-search .icon { color: #8fa6d6; }
.topbar-search input {
  flex: 1;
  border: none;
  background: none;
  color: #fff;
  font-size: 14px;
  outline: none;
}
.topbar-search input::placeholder { color: #8b97ad; }
.topbar-search:focus-within { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.25); }

.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #aab4c6; flex-shrink: 0; }

.avatar-wrap { position: relative; }
.avatar-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-btn:hover { filter: brightness(1.1); }
.avatar-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(8, 15, 30, 0.2);
  z-index: 30;
  overflow: hidden;
}
.avatar-menu-header { padding: 14px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); word-break: break-all; }
.avatar-menu a { display: flex; align-items: center; gap: 10px; padding: 11px 16px; color: var(--text); font-size: 14px; font-weight: 500; }
.avatar-menu a:hover { background: var(--bg); text-decoration: none; }
.avatar-menu .icon { color: var(--muted); }

.workspace-tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--border); }
.workspace-tab { display: flex; align-items: center; gap: 8px; padding: 12px 16px; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.workspace-tab:hover { color: var(--text); text-decoration: none; }
.workspace-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Notification bell */
.notif-wrap { position: relative; }
.notif-bell {
  position: relative;
  border: none;
  background: none;
  font-size: 17px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  color: #cfd7e4;
  filter: grayscale(1) brightness(1.6);
}
.notif-bell:hover { background: rgba(255, 255, 255, 0.08); }
.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 999px;
  min-width: 16px;
  text-align: center;
}
.notif-badge.badge-high { background: var(--danger); }
.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(8, 15, 30, 0.18);
  z-index: 20;
  text-align: left;
}
.notif-panel-header { padding: 12px 16px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); color: var(--text); }
.notif-list { max-height: 280px; overflow-y: auto; }
.notif-empty { padding: 16px; color: var(--muted); font-size: 13px; margin: 0; }
.notif-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; }
.notif-item:hover { background: var(--bg); text-decoration: none; }
.notif-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-panel-footer { display: block; padding: 10px 16px; font-size: 13px; text-align: center; border-top: 1px solid var(--border); }

.level-chip { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 3px 8px; border-radius: 4px; flex-shrink: 0; }
.level-chip.level-high { background: #fdeceb; color: #9a2c23; }
.level-chip.level-medium { background: #fdf3e2; color: #92650c; }

.rules-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.rules-table th, .rules-table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.rules-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: #f8f9fb; }
.rules-table tr:last-child td { border-bottom: none; }

.app-shell { display: flex; min-height: calc(100vh - 96px); }

.sidebar {
  width: 226px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
}
.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: var(--primary);
  color: #fff;
  padding: 11px;
  border-radius: 6px;
  font-weight: 600;
  margin-bottom: 18px;
}
.compose-btn:hover { background: var(--primary-dark); text-decoration: none; }
.account-list { margin-bottom: 4px; }
.account-block { margin-bottom: 4px; }
.account-header { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.account-header:hover { background: var(--bg); text-decoration: none; }
.account-block.active .account-header { color: var(--text); }
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-header-row { display: flex; align-items: center; }
.account-header-row .account-header { flex: 1; min-width: 0; }
.account-edit-link { display: flex; align-items: center; justify-content: center; padding: 8px; border-radius: 6px; color: var(--muted); opacity: 0; transition: opacity .15s; }
.account-header-row:hover .account-edit-link { opacity: 1; }
.account-edit-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.account-edit-link .icon { width: 14px; height: 14px; }
.account-block .folder-list { margin-left: 10px; padding-left: 10px; border-left: 2px solid var(--border); }

.folder-list { list-style: none; margin: 0 0 8px; padding: 0; }
.folder-list li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.folder-list li a:hover { background: var(--bg); text-decoration: none; }
.folder-list li.active a { background: var(--unread-bg); color: var(--primary); font-weight: 700; border-left-color: var(--primary); }
.folder-list .icon { color: var(--muted); }
.folder-list li.active .icon { color: var(--primary); }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  cursor: pointer;
}
.sidebar-section-toggle .icon { width: 14px; height: 14px; transition: transform 0.15s; }
.sidebar-section-toggle.collapsed .icon { transform: rotate(-90deg); }

.sidebar-new-folder-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}
.sidebar-new-folder-toggle:hover { background: var(--bg); color: var(--text); }
#new-folder-form { display: flex; gap: 6px; padding: 8px 12px; }
#new-folder-form input { margin-top: 0; padding: 7px 10px; font-size: 13px; text-transform: none; }
#new-folder-form .save-btn { padding: 7px 12px; font-size: 13px; }

.sidebar-utilities { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-utilities a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.sidebar-utilities a:hover { background: var(--bg); color: var(--text); text-decoration: none; }

.star-form { display: flex; align-items: center; margin: 0; }
.star-btn { background: none; border: none; padding: 2px; cursor: pointer; color: #c3cad6; display: flex; }
.star-btn:hover { color: #d9a441; }
.star-btn.starred { color: #e0a52c; }

.importance-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.importance-dot.importance-high { background: var(--danger); }
.importance-dot.importance-medium { background: #d99a2b; }

/* Mail list */
.mail-list-pane { flex: 1; padding: 24px 32px; max-width: 960px; }
.mail-list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.mail-list-header h2 { margin: 0; }

.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.search-form input[type=text] { flex: 1; margin-top: 0; text-transform: none; }

.bulk-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.bulk-select-all { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.bulk-bar select { width: auto; margin-top: 0; padding: 9px 12px; text-transform: none; }

.mail-row-wrap { display: flex; align-items: center; gap: 10px; }
.mail-row-wrap .mail-select { flex-shrink: 0; width: 16px; height: 16px; cursor: pointer; margin: 0 0 0 4px; accent-color: var(--primary); }
.mail-row-wrap .mail-row { flex: 1; min-width: 0; }

.mail-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.mail-row { display: grid; grid-template-columns: 220px 1fr 160px; gap: 16px; padding: 13px 18px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 14px; }
.mail-row:last-child { border-bottom: none; }
.mail-row:hover { background: var(--bg); text-decoration: none; }
.mail-row.unread { background: var(--unread-bg); font-weight: 700; }
.mail-from, .mail-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); text-align: right; font-weight: 400; }

.empty-state { color: var(--muted); padding: 40px 0; text-align: center; }
.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

/* Message view */
.message-pane { flex: 1; padding: 24px 32px; max-width: 960px; }
.back-link { display: inline-block; margin-bottom: 16px; font-size: 14px; }
.message-header { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.message-header h2 { margin: 0 0 4px; font-size: 19px; }
.message-header p { margin: 4px 0; font-size: 14px; color: var(--muted); }
.message-header-top { display: flex; align-items: flex-start; gap: 14px; }
.sender-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.message-header-meta { flex: 1; min-width: 0; }
.message-header p.sender-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--text); }
.origin-badge { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 4px; }
.origin-badge.origin-internal { background: var(--unread-bg); color: var(--primary); }
.origin-badge.origin-external { background: #fdf3e2; color: #92650c; }
.origin-notice { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; color: #92650c; }
.message-header-top .star-btn { margin-top: 4px; }

.message-actions { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.message-actions form { margin: 0; }

.attachment-list { margin-bottom: 16px; }
.attachment-list > strong { display: block; margin-bottom: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.attachment-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.attachment-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  min-width: 160px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.attachment-card:hover { text-decoration: none; border-color: var(--primary); box-shadow: 0 4px 14px rgba(29, 78, 216, 0.12); }
.attachment-card .icon { color: var(--muted); }
.attachment-card-info { display: flex; flex-direction: column; min-width: 0; }
.attachment-card-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.attachment-card-size { font-size: 12px; color: var(--muted); }
.message-body-frame { width: 100%; min-height: 400px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }

/* Compose */
.compose-pane { flex: 1; padding: 24px 32px; max-width: 820px; }
.compose-pane form { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.editor-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 6px; }
.editor-toolbar button, .editor-toolbar select { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.editor-toolbar button:hover { background: var(--bg); }
.editor-surface { min-height: 220px; border: 1px solid var(--border); border-radius: 6px; padding: 14px; background: #fff; font-size: 14px; margin-bottom: 14px; }
.editor-surface:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15); }
.editor-source { min-height: 220px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 6px; padding: 14px; }

@media (max-width: 900px) {
  .topbar-search { display: none; }
  .workspace-tabs { padding: 0 12px; }
}

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; gap: 8px; padding: 10px 14px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .compose-btn { margin-bottom: 0; white-space: nowrap; }
  .folder-list { display: flex; gap: 4px; margin-bottom: 0; }
  .sidebar-section-toggle, .sidebar-new-folder-toggle, #new-folder-form, .sidebar-utilities { display: none; }
  .account-header { display: none; }
  .account-edit-link { display: none; }
  .account-block:not(.active) { display: none; }
  .account-block .folder-list { margin-left: 0; padding-left: 0; border-left: none; }
  .mail-row { grid-template-columns: 1fr; gap: 2px; }
  .mail-date { text-align: left; }
  .mail-list-pane, .message-pane, .compose-pane { padding: 16px; }
  .message-header-top { flex-wrap: wrap; }
}
