:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: rgba(15, 23, 42, 0.07);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent: #3182f6;
  --accent-hover: #1b64da;
  --accent-soft: rgba(49, 130, 246, 0.1);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --warn: #d97706;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --shadow-card: 0 4px 20px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
  --shadow-modal: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
  --radius-card: 16px;
  --radius-control: 12px;
  --radius-pill: 9999px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(49, 130, 246, 0.08), transparent 45%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 32px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark,
.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 13px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.login-form,
.compose-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="search"],
select.form-select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(49, 130, 246, 0.14);
}

.input-readonly {
  background: var(--surface-muted) !important;
  color: var(--text-secondary) !important;
}

.mailbox-select {
  width: auto !important;
  min-width: 150px;
  max-width: 210px;
  min-height: 38px !important;
  padding: 6px 10px !important;
  font-size: 12px !important;
  font-weight: 600;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  background: var(--danger-soft);
  color: #b91c1c;
  font-size: 13px;
  font-weight: 500;
}

/* Buttons & Pills */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 10px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary-soft {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-primary-soft:hover:not(:disabled) {
  background: rgba(49, 130, 246, 0.16);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-muted);
}

.btn-ghost.active {
  background: var(--accent-soft);
  border-color: rgba(49, 130, 246, 0.3);
  color: var(--accent);
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: #dc2626;
}

.btn-danger-soft:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.18);
}

.btn-success-soft {
  background: var(--success-soft);
  color: #047857;
}

.btn-pill {
  border-radius: var(--radius-pill);
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.pill-neutral {
  background: var(--surface-muted);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.pill-ok {
  background: var(--success-soft);
  color: #047857;
}

.pill-warn {
  background: var(--warn-soft);
  color: #b45309;
}

.pill-danger {
  background: var(--danger-soft);
  color: #dc2626;
}

.pill-user {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* Workspace Layout */
.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100vw;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.topbar-title small {
  color: var(--text-secondary);
  font-weight: 500;
}

.status-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  width: 220px;
}

.search-box input {
  padding-right: 36px;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

/* 3-Pane Grid */
.mail-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 236px 380px minmax(0, 1fr);
  gap: 14px;
  padding: 14px 20px;
  overflow: hidden;
}

.sidebar,
.list-pane,
.detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sidebar */
.sidebar-compose-wrap {
  padding: 16px 14px 8px;
}

.folder-nav {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.folder-item {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background-color 0.14s ease;
}

.folder-item:hover {
  background: var(--surface-muted);
}

.folder-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.folder-count {
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.folder-item.active .folder-count {
  background: var(--accent);
  color: #ffffff;
}

.sidebar-mobile-actions {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.account-chip {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Message List */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.pane-header-title {
  min-width: 0;
}

.pane-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.pane-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.muted-text {
  color: var(--text-secondary);
  font-size: 12px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg-card {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.msg-card:hover {
  background: var(--bg);
}

.msg-card.active {
  background: var(--accent-soft);
  border-color: rgba(49, 130, 246, 0.25);
}

.msg-card.unread {
  background: #f8fbff;
}

.msg-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-sender {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.msg-card.unread .msg-sender,
.msg-card.unread .msg-subject {
  color: var(--text-primary);
  font-weight: 700;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.msg-sender-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.msg-subject-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-subject {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.star-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: #cbd5e1;
  padding: 2px;
}

.star-btn.starred {
  color: #f59e0b;
}

.msg-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

/* Detail Pane */
.detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-card {
  max-width: 340px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-card h3 {
  margin: 0 0 6px;
  color: var(--text-primary);
  font-size: 17px;
}

.detail-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 18px 22px;
  gap: 16px;
}

.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-header-card {
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.detail-subject {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.detail-meta-grid {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.detail-meta-grid > div {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-label {
  min-width: 66px;
  color: var(--text-secondary);
  font-weight: 600;
}

.meta-value {
  color: var(--text-primary);
  word-break: break-all;
}

.attachments-card {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.attachments-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.att-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.body-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tab-group {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-muted);
  border-radius: var(--radius-control);
}

.tab-btn {
  min-height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.body-viewer {
  flex: 1;
  min-height: 340px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.html-frame {
  width: 100%;
  flex: 1;
  min-height: 340px;
  border: none;
  background: #ffffff;
}

.text-pre {
  margin: 0;
  padding: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  overflow-y: auto;
  flex: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border);
  padding: 24px;
}

.modal-card-sm {
  max-width: 440px;
}

.modal-card-lg {
  max-width: 780px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.compose-notice {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: #92400e;
  font-size: 13px;
  font-weight: 500;
}

.guide-box {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(217, 119, 6, 0.25);
  background: #fffbeb;
  color: #78350f;
  font-size: 13px;
}

.guide-box summary {
  font-weight: 700;
  cursor: pointer;
}

.guide-steps {
  margin: 8px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guide-steps code {
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* Admin Users Modal */
.admin-create-card {
  padding: 16px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.admin-create-title {
  font-weight: 700;
  font-size: 14px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.admin-create-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.admin-list-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.admin-user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.admin-user-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-user-name {
  font-weight: 700;
  font-size: 15px;
}

.admin-user-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  z-index: 80;
  max-width: calc(100vw - 32px);
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: inline-flex;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 40;
}

.fab-compose {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 22px;
  box-shadow: 0 10px 24px rgba(49, 130, 246, 0.4);
  cursor: pointer;
  z-index: 35;
}

/* Responsive Mobile (< 1024px) */
@media (max-width: 1023px) {
  .mobile-only {
    display: inline-flex;
  }
  .mobile-only-block {
    display: flex;
  }
  .desktop-only {
    display: none !important;
  }

  .topbar {
    padding: 10px 14px;
  }

  .search-box {
    width: 100%;
    flex: 1 1 180px;
  }

  .topbar-actions {
    width: 100%;
  }

  .mail-grid {
    grid-template-columns: 1fr;
    padding: 10px 12px;
    gap: 0;
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 270px;
    max-width: 82vw;
    border-radius: 0 16px 16px 0;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }

  .detail-pane {
    display: none;
  }

  .mail-grid.mobile-detail-open .list-pane {
    display: none;
  }

  .mail-grid.mobile-detail-open .detail-pane {
    display: flex;
  }

  .detail-content {
    padding: 14px;
  }

  .login-card {
    padding: 24px;
  }

  .admin-form-grid {
    grid-template-columns: 1fr;
  }
}
