/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --border: #e5e7eb;
  --border2: #d1d5db;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 4px 12px rgba(0,0,0,.1);
  --radius: 8px;
  --sidebar-w: 220px;
  --list-w: 320px;
  --header-h: 52px;
}

html, body { height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ===== SCREENS ===== */
.screen { display: flex; flex-direction: column; height: 100vh; }
.screen.hidden { display: none !important; }

/* ===== LOGIN ===== */
#login-screen { align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: var(--surface); border-radius: 16px; padding: 2rem; width: 420px; max-width: calc(100vw - 2rem); box-shadow: var(--shadow); }
.login-logo { display: flex; align-items: center; gap: .6rem; font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-bottom: 1.5rem; justify-content: center; }
.login-logo svg { width: 36px; height: 36px; }
.tab-bar { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab { flex: 1; padding: .6rem; background: none; border: none; cursor: pointer; font-size: .9rem; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .2s; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.login-form { display: none; flex-direction: column; gap: 1rem; }
.login-form.active { display: flex; }
.form-row { display: flex; flex-direction: column; gap: .3rem; }
.form-row label { font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=number] {
  padding: .6rem .8rem; border: 1.5px solid var(--border2); border-radius: var(--radius);
  font-size: .95rem; transition: border-color .2s; outline: none; width: 100%;
}
.form-row input:focus { border-color: var(--primary); }
.form-row input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); margin-top: .3rem; }
.error-msg { color: var(--danger); font-size: .85rem; padding: .5rem .75rem; background: #fef2f2; border-radius: var(--radius); border: 1px solid #fecaca; }
.success-msg { color: var(--success); font-size: .85rem; padding: .5rem .75rem; background: #f0fdf4; border-radius: var(--radius); border: 1px solid #bbf7d0; }

/* ===== BUTTONS ===== */
.btn-primary   { background: var(--primary); color: #fff; border: none; border-radius: var(--radius); padding: .6rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .2s; }
.btn-primary:hover  { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem 1rem; font-size: .9rem; cursor: pointer; }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; border: none; border-radius: var(--radius); padding: .5rem 1rem; font-size: .9rem; cursor: pointer; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-full { width: 100%; }
.icon-btn { background: none; border: none; cursor: pointer; padding: .4rem .5rem; border-radius: 6px; font-size: .95rem; color: var(--text-muted); transition: background .15s; }
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ===== HEADER ===== */
#app-header { height: var(--header-h); display: flex; align-items: center; gap: .75rem; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 100; flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: .5rem; width: var(--sidebar-w); flex-shrink: 0; }
.app-logo { display: flex; align-items: center; gap: .4rem; font-weight: 700; font-size: 1rem; color: var(--primary); }
.app-logo svg { width: 22px; height: 22px; }
.search-bar { flex: 1; display: flex; align-items: center; gap: .4rem; background: var(--surface2); border: 1.5px solid var(--border); border-radius: 24px; padding: .25rem .75rem; max-width: 480px; }
.search-bar input { border: none; background: none; outline: none; flex: 1; font-size: .9rem; }
.header-right { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.username-display { font-size: .85rem; color: var(--text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-wrap { position: relative; }
.avatar-btn { width: 32px; height: 32px; border-radius: 50% !important; background: var(--primary-light) !important; color: var(--primary) !important; }
.dropdown { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 160px; z-index: 200; overflow: hidden; }
.dropdown-item { display: block; width: 100%; text-align: left; padding: .6rem 1rem; font-size: .9rem; background: none; border: none; cursor: pointer; color: var(--text); }
.dropdown-item:hover { background: var(--surface2); }

/* ===== MAIN LAYOUT ===== */
#main-layout { display: flex; flex: 1; overflow: hidden; }

/* ===== SIDEBAR ===== */
#sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: .5rem; padding: .75rem .5rem; overflow-y: auto; flex-shrink: 0; transition: width .2s; }
#sidebar.collapsed { width: 0; padding: 0; overflow: hidden; }
.btn-compose { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .6rem 1rem; background: var(--primary); color: #fff; border: none; border-radius: 24px; font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .2s; }
.btn-compose:hover { background: var(--primary-hover); }
#folder-list { display: flex; flex-direction: column; gap: 1px; margin-top: .5rem; }
.folder-item { display: flex; align-items: center; gap: .5rem; padding: .45rem .75rem; border-radius: 6px; cursor: pointer; font-size: .875rem; color: var(--text-muted); transition: all .15s; user-select: none; }
.folder-item:hover { background: var(--surface2); color: var(--text); }
.folder-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.folder-item .fi { width: 20px; flex-shrink: 0; }
.folder-item .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== MESSAGE LIST ===== */
#message-list-pane { width: var(--list-w); border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); flex-shrink: 0; }
#message-list-header { display: flex; align-items: center; justify-content: space-between; padding: .6rem .75rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: .9rem; flex-shrink: 0; }
.list-actions { display: flex; align-items: center; gap: .25rem; }
#message-list { flex: 1; overflow-y: auto; }
.msg-item { display: flex; align-items: flex-start; gap: .5rem; padding: .7rem .75rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; position: relative; }
.msg-item:hover { background: var(--surface2); }
.msg-item.active { background: var(--primary-light); }
.msg-item.unread .ms, .msg-item.unread .mj { font-weight: 700; color: var(--text); }
.msg-item.flagged::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: #f59e0b; border-radius: 2px; }
.msg-cb { margin-top: 2px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.mc { flex: 1; min-width: 0; }
.mt { display: flex; justify-content: space-between; gap: .25rem; }
.ms { font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.md { font-size: .75rem; color: var(--text-light); flex-shrink: 0; }
.mj { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); margin-top: .15rem; }
.mi { display: flex; gap: .2rem; margin-top: .1rem; font-size: .75rem; }
.ud { width: 8px; height: 8px; background: var(--primary); border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
#pagination { display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem; border-top: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.page-btn { padding: .3rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: .8rem; }
.page-btn:hover:not(:disabled) { background: var(--surface2); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-info { font-size: .75rem; color: var(--text-muted); }
.select-all-wrap { display: flex; align-items: center; }

/* ===== MESSAGE VIEW ===== */
#message-view-pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); }
#message-view-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-state { text-align: center; color: var(--text-muted); }
.empty-state svg { width: 80px; height: 80px; margin-bottom: 1rem; }
#message-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#msg-toolbar { display: flex; align-items: center; gap: .25rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.toolbar-sep { flex: 1; }
.move-wrap { position: relative; }
#move-dropdown { position: absolute; right: 0; top: calc(100% + 2px); min-width: 160px; max-height: 300px; overflow-y: auto; }
#msg-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#msg-subject { font-size: 1.2rem; font-weight: 700; color: var(--text); margin-bottom: .6rem; }
#msg-meta { display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; color: var(--text-muted); }
#msg-meta strong { color: var(--text); }
#msg-attachments { padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: .5rem; flex-shrink: 0; }
.att-chip { display: flex; align-items: center; gap: .4rem; padding: .3rem .65rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; text-decoration: none; color: var(--text); font-size: .8rem; transition: background .15s; }
.att-chip:hover { background: var(--border); }
.att-sz { color: var(--text-muted); }
#msg-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
#msg-body iframe { width: 100%; border: none; min-height: 400px; }

/* ===== COMPOSE ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 300; }
.modal { position: fixed; bottom: 0; right: 1.5rem; z-index: 400; width: 600px; max-width: calc(100vw - 2rem); }
.modal-box { background: var(--surface); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 85vh; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; background: var(--primary); color: #fff; border-radius: 12px 12px 0 0; font-weight: 600; }
.modal-close { background: none; border: none; color: rgba(255,255,255,.8); cursor: pointer; font-size: 1.1rem; padding: .2rem .4rem; border-radius: 4px; }
.modal-close:hover { background: rgba(255,255,255,.1); color: #fff; }
.compose-body { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.compose-field { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: .4rem .75rem; }
.compose-field label { width: 50px; font-size: .8rem; color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.compose-field input { flex: 1; border: none; outline: none; font-size: .9rem; }
.compose-attachments { display: flex; flex-wrap: wrap; gap: .4rem; padding: .4rem .75rem; border-bottom: 1px solid var(--border); }
.compose-attachments:empty { display: none; }
.catt { display: flex; align-items: center; gap: .3rem; padding: .2rem .5rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; font-size: .8rem; }
.catt-rm { background: none; border: none; cursor: pointer; color: var(--text-muted); }
.compose-editor { flex: 1; padding: .75rem; outline: none; font-size: .9rem; line-height: 1.6; overflow-y: auto; min-height: 200px; }
.modal-footer { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; border-top: 1px solid var(--border); }
#compose-status { font-size: .85rem; padding: .3rem .6rem; border-radius: 6px; }
#compose-status.sending { color: var(--primary); background: var(--primary-light); }
#compose-status.ok  { color: var(--success); background: #f0fdf4; }
#compose-status.err { color: var(--danger);  background: #fef2f2; }

/* ===== ADMIN ===== */
#admin-screen { background: var(--bg); }
.admin-header { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; gap: .5rem; }
.admin-content { display: flex; flex: 1; overflow: hidden; }
.admin-sidebar { width: 200px; background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .5rem; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.admin-nav { display: block; width: 100%; text-align: left; padding: .6rem .75rem; background: none; border: none; border-radius: 6px; cursor: pointer; font-size: .9rem; color: var(--text-muted); }
.admin-nav:hover { background: var(--surface2); }
.admin-nav.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.admin-main { flex: 1; overflow-y: auto; padding: 1.5rem; }
.admin-section { display: none; }
.admin-section.active { display: block; }
.admin-section h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: .35rem; }
.section-desc { font-size: .85rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.section-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card h3 { font-size: .95rem; font-weight: 600; margin: 1rem 0 .75rem; }
.card h3:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.user-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .5rem; display: flex; align-items: center; justify-content: space-between; }
.user-card-info h4 { font-size: .95rem; font-weight: 600; }
.user-card-info p { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }
.user-card-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.empty-list { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .9rem; }

/* ===== LOADING ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 2rem; color: var(--text-muted); gap: .5rem; }
.loading::after { content: ''; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SEARCH INFO ===== */
.search-info { padding: .5rem .75rem; font-size: .8rem; color: var(--text-muted); background: #fffbeb; border-bottom: 1px solid #fde68a; }

/* ===== SETUP ===== */
.setup-badge { display: inline-block; background: #fef3c7; color: #92400e; border: 1px solid #fde68a; border-radius: 20px; font-size: .78rem; font-weight: 700; padding: .2rem .75rem; margin-bottom: .75rem; }
.setup-intro { font-size: .875rem; color: var(--text-muted); margin-bottom: 1.25rem; line-height: 1.5; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
