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

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Explicit caret-color everywhere text can be typed — without it the browser
   picks its own (often based on prefers-color-scheme / native form-control
   heuristics rather than this page's actual theme), which is what made the
   text cursor render white-on-white and effectively invisible in light theme.
   var(--text) already resolves correctly per theme, same as the text itself. */
input, textarea, [contenteditable] { caret-color: var(--text); }

:root {
    --bg:       #060c1a;
    --bg2:      #0d1830;
    --surface:  #111827;
    --surface2: #1a2540;
    --accent:   #3b82f6;
    --accent2:  #06b6d4;
    --accent-hover: #2563eb;
    --text:     #f8fafc;
    --text-muted: #94a3b8;
    --border:   rgba(255,255,255,0.08);
    --border2:  rgba(59,130,246,0.2);
    --unread-bg: #0d1830;
    --radius:   10px;
    --shadow:   0 2px 8px rgba(0,0,0,0.3);
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
    --bg:       #f1f5f9;
    --bg2:      #e2e8f0;
    --surface:  #ffffff;
    --surface2: #f8fafc;
    --accent:   #2563eb;
    --accent2:  #0891b2;
    --accent-hover: #1d4ed8;
    --text:     #0f172a;
    --text-muted: #64748b;
    --border:   rgba(0,0,0,0.1);
    --border2:  rgba(37,99,235,0.25);
    --unread-bg: #eff6ff;
    --shadow:   0 2px 8px rgba(0,0,0,0.08);
}
[data-theme="light"] body { color-scheme: light; }
[data-theme="light"] .sidebar { background: var(--surface); border-color: var(--border); }
[data-theme="light"] .topbar { background: var(--surface); border-color: var(--border); }
[data-theme="light"] .msg-item { color: var(--text); }
[data-theme="light"] .msg-item:hover { background: var(--bg2); }
[data-theme="light"] .login-card { background: var(--surface); }
[data-theme="light"] .login-card input { background: var(--bg); color: var(--text); }
[data-theme="light"] .settings-card { background: var(--surface); border-color: var(--border); }
[data-theme="light"] input, [data-theme="light"] textarea, [data-theme="light"] select { background: var(--bg); color: var(--text); border-color: var(--border); }
[data-theme="light"] pre, [data-theme="light"] code { background: var(--bg2); border-color: var(--border); color: var(--text); }
/* Base rule uses a fixed white rgba() that is invisible on the light theme's
   white sidebar — override with a dark equivalent. */
[data-theme="light"] .sidebar-section-title { color: rgba(0,0,0,0.35); }

/* ===== BLACK THEME ===== */
[data-theme="black"] {
    --bg:       #000000;
    --bg2:      #0a0a0a;
    --surface:  #111111;
    --surface2: #1a1a1a;
    --accent:   #3b82f6;
    --accent2:  #06b6d4;
    --accent-hover: #2563eb;
    --text:     #f8fafc;
    --text-muted: #71717a;
    --border:   rgba(255,255,255,0.07);
    --border2:  rgba(59,130,246,0.2);
    --unread-bg: #0a0a0a;
    --shadow:   0 2px 8px rgba(0,0,0,0.5);
}

body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }

/* ===== LOGIN ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.login-logo h1 span { background: linear-gradient(135deg, #3b82f6, #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem; }
.login-credit { font-size: 0.72rem !important; margin-top: 0.3rem !important; }
.login-credit a { color: var(--accent); text-decoration: none; }
.login-credit a:hover { text-decoration: underline; }
.sidebar-credit { padding: 0.4rem 1.25rem; }
.sidebar-credit a { font-size: 0.68rem; color: var(--text-muted); opacity: 0.5; transition: opacity 0.15s; }
.sidebar-credit a:hover { opacity: 1; }
.sidebar-logout-btn { background: none; border: none; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 0.65rem; padding: 0; font-family: inherit; width: 100%; transition: color 0.15s; }
.sidebar-logout-btn:hover { color: var(--text); }
.login-card label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.05em; }
.login-card input[type=email],
.login-card input[type=password],
.login-card input[type=text],
.login-card input[type=number] {
    width: 100%; padding: 0.75rem 1rem; border: 1.5px solid var(--border); border-radius: 8px;
    font-size: 0.95rem; font-family: inherit; color: var(--text); background: var(--bg2);
    transition: border-color 0.2s; margin-bottom: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-options { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-muted); cursor: pointer; }
.checkbox-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.forgot-link { font-size: 0.8rem; color: var(--accent); }
.forgot-link:hover { text-decoration: underline; }
.advanced-toggle { background: none; border: none; color: var(--text-muted); font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 0.35rem; font-family: inherit; padding: 0; transition: color 0.15s; }
.advanced-toggle:hover { color: var(--text); }
.imap-row { display: flex; gap: 0.75rem; }
.imap-host { flex: 1 1 auto; }
.imap-port { flex: 0 0 90px; }
.imap-row label { margin-top: 0; }
.set-default-btn { background: none; border: 1px solid var(--border); color: var(--text-muted); font-size: 0.75rem; border-radius: 6px; padding: 0.4rem 0.7rem; cursor: pointer; display: flex; align-items: center; gap: 0.35rem; font-family: inherit; transition: all 0.15s; margin-bottom: 0.75rem; }
.set-default-btn:hover { border-color: var(--accent); color: var(--accent); }
.set-default-status { font-size: 0.75rem; min-height: 1em; margin-bottom: 0.5rem; }
.btn-login { width: 100%; padding: 0.85rem; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 700; cursor: pointer; transition: background 0.2s; font-family: inherit; }
.btn-login:hover { background: var(--accent-hover); }
.flash-error { background: rgba(220,38,38,0.1); border: 1px solid rgba(220,38,38,0.25); color: #f87171; padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; }
.flash-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.25); color: #4ade80; padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; }
.account-list-mini { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.account-chip { display: flex; align-items: center; gap: 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: 20px; padding: 0.35rem 0.75rem 0.35rem 0.35rem; font-size: 0.78rem; color: var(--text-muted); transition: border-color 0.15s; }
.account-chip:hover { border-color: var(--accent); color: var(--text); }
.account-chip-avatar { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.65rem; font-weight: 700; flex-shrink: 0; }

/* ===== APP LAYOUT ===== */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== ACCOUNT SWITCHER ===== */
.account-switcher { border-bottom: 1px solid var(--border); padding: 0.5rem 0; }
.account-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 1rem; text-decoration: none; color: var(--text-muted); font-size: 0.78rem; transition: background 0.12s; width: 100%; text-align: left; background: none; border: none; cursor: pointer; font-family: inherit; box-sizing: border-box; }
.account-item:hover { background: rgba(59,130,246,0.08); color: var(--text); }
.account-item.active { color: var(--text); cursor: default; }
.account-avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; flex-shrink: 0; }
.account-avatar.add { background: rgba(255,255,255,0.08); color: var(--text-muted); font-size: 1rem; }
.account-email { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-check { color: var(--accent); font-size: 0.75rem; flex-shrink: 0; }

/* ===== SIDEBAR ===== */
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; transition: transform 0.25s; }
.sidebar-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sidebar-logo { padding: 1.25rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border); }
.sidebar-logo h1 { font-size: 1.15rem; font-weight: 700; }
.sidebar-logo h1 span { background: linear-gradient(135deg, #3b82f6, #06b6d4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sidebar-user { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.sidebar-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1.5px solid var(--border); flex-shrink: 0; }
.sidebar-user span { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-avatar-img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 1.5px solid var(--border); flex-shrink: 0; }
.compose-btn { margin: 0.875rem 1rem; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0.65rem 1rem; font-size: 0.875rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; font-family: inherit; transition: background 0.2s; text-decoration: none; justify-content: center; }
.compose-btn:hover { background: var(--accent-hover); }
.sidebar-section { padding: 0.35rem 0; }
.sidebar-section-title { display: flex; align-items: center; padding: 0.5rem 1.25rem 0.2rem; font-size: 0.68rem; font-weight: 600; color: rgba(255,255,255,0.25); text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar-folder-del { display: none; position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.75rem; padding: 2px 4px; line-height: 1; }
.sidebar-link:hover .sidebar-folder-del { display: block; }
.sidebar-folder-del:hover { color: #f87171; }
.sidebar-link { display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 1.25rem; color: var(--text-muted); text-decoration: none; font-size: 0.85rem; transition: background 0.15s, color 0.15s; position: relative; }
.sidebar-link:hover { background: rgba(59,130,246,0.08); color: var(--text); }
.sidebar-link.active { background: rgba(59,130,246,0.15); color: var(--accent); font-weight: 600; }
.sidebar-link.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 0 3px 3px 0; }
.sidebar-link .badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 0.68rem; font-weight: 700; border-radius: 10px; padding: 0.1rem 0.45rem; min-width: 20px; text-align: center; }
.sidebar-link svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.7; }
.sidebar-link.active svg { opacity: 1; }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-footer a { color: var(--text-muted); font-size: 0.78rem; display: flex; align-items: center; gap: 0.5rem; transition: color 0.15s; }
.sidebar-footer a:hover { color: #f87171; }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.75rem 1.25rem; display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.topbar-menu-btn { display: none; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.25rem; }
.topbar-title { font-size: 0.95rem; font-weight: 600; color: var(--text); flex: 1; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-icon { background: none; border: 1px solid var(--border); border-radius: 7px; padding: 0.4rem 0.7rem; cursor: pointer; font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; font-family: inherit; transition: border-color 0.15s, color 0.15s; text-decoration: none; }
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.content { flex: 1; overflow-y: auto; }

/* ===== SEARCH BAR ===== */
/* Pill-shaped, icon-inside-input search box (Gmail-style) rather than a
   bordered bar as its own row — sitting directly under the topbar with no
   border of its own, it read as a disconnected boxed-off section instead of
   feeling like part of the same header. */
.search-bar { display: flex; align-items: center; justify-content: center; padding: 0.65rem 1.25rem; background: var(--bg2); flex-shrink: 0; }
.search-bar-inner { position: relative; display: flex; align-items: center; width: 100%; max-width: 480px; }
.search-bar-inner .search-icon { position: absolute; left: 0.85rem; color: var(--text-muted); pointer-events: none; }
.search-bar input { width: 100%; background: var(--surface); border: 1px solid transparent; border-radius: 999px; padding: 0.5rem 2.3rem; font-size: 0.85rem; color: var(--text); font-family: inherit; }
.search-bar input::placeholder { color: var(--text-muted); }
.search-bar input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.search-bar-clear { position: absolute; right: 0.4rem; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.3rem; border-radius: 50%; display: none; align-items: center; justify-content: center; }
.search-bar-clear.visible { display: flex; }
.search-bar-clear:hover { color: var(--text); background: var(--border); }

/* ===== MESSAGE LIST ===== */
.msg-list { list-style: none; }
.msg-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.msg-row .msg-item { flex: 1; border-bottom: none; }
.msg-select-cb { display: none; align-items: center; padding: 0 0 0 1rem; cursor: pointer; flex-shrink: 0; }
.msg-list.select-mode .msg-select-cb { display: flex; }
.msg-list.select-mode .msg-row:has(.msg-select-cb input:checked) { background: rgba(59,130,246,0.1); }
.msg-select-cb input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.msg-star { display: flex; align-items: center; justify-content: center; width: 32px; flex-shrink: 0; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }
.msg-star svg { width: 15px; height: 15px; }
.msg-star:hover { color: #fbbf24; }
.msg-star.active { color: #fbbf24; }
.msg-star:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.msg-item { display: grid; grid-template-columns: 38px 1fr 70px; gap: 0.75rem; align-items: center; padding: 0.7rem 1.25rem; cursor: pointer; background: transparent; transition: background 0.1s; text-decoration: none; color: inherit; position: relative; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.msg-item.long-pressing { background: rgba(255,255,255,0.06); }
.msg-item:hover { background: rgba(255,255,255,0.03); }
.msg-item.unread { background: var(--unread-bg); }
.msg-item.unread .msg-from { font-weight: 700; color: var(--text); }
.msg-item.unread .msg-subject { color: var(--text); }
.msg-item.unread::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); border-radius: 0 2px 2px 0; }
.msg-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; flex-shrink: 0; }
.msg-body { min-width: 0; }
.msg-from { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-subject { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 0.1rem; }
.msg-date { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; text-align: right; }
/* Saapumisaika omana rivinään aiheen alla (js/aika.js) — näkyy myös puhelimella,
   jossa oikean reunan .msg-date-sarake on piilotettu. Rivit ilman .msg-date-saraketta
   eivät varaa sille tyhjää 70 px:n palstaa. */
.msg-when { font-size: 0.7rem; color: var(--text-muted); opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.msg-item:not(:has(> .msg-date)) { grid-template-columns: 38px 1fr; }
.empty-state { text-align: center; padding: 5rem 2rem; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 1rem; opacity: 0.2; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ===== PAGINATION ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 1rem; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.pagination a, .pagination span { padding: 0.35rem 0.65rem; border-radius: 6px; font-size: 0.78rem; text-decoration: none; color: var(--text-muted); border: 1px solid var(--border); transition: border-color 0.15s, color 0.15s; }
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.pagination-ellipsis { border: none !important; padding: 0 0.15rem !important; }
.pagination-jump { display: inline-flex; align-items: center; gap: 0.3rem; margin-left: 0.3rem; border: none !important; padding: 0 !important; }
.pagination-jump input { width: 52px; background: var(--bg2,#0d1830); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 0.3rem 0.4rem; font-size: 0.78rem; font-family: inherit; }
.pagination-jump button { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 0.35rem 0.6rem; font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.pagination-jump button:hover { opacity: 0.85; }

/* ===== MESSAGE VIEW ===== */
.msg-nav-btns { display:flex; gap:0.35rem; margin-right:0.5rem; }
.msg-nav-btn { font-size:1.1rem; line-height:1; }
.msg-nav-btn:disabled { opacity:0.3; cursor:default; }
/* Left/right arrows are the desktop (mouse-driven) equivalent of the swipe
   gesture on the message view — on a touch device they'd just be redundant
   tap targets crowding the topbar, since swiping is the natural gesture there. */
@media (hover: none) and (pointer: coarse) { .msg-nav-btns { display:none; } }
.message-view { padding: 1.25rem; max-width: 860px; margin: 0 auto; }
.message-header { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem; }
.message-subject { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; line-height: 1.3; }
.message-meta { display: flex; align-items: flex-start; gap: 0.75rem; }
.message-avatar { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.message-from-block { flex: 1; min-width: 0; }
.message-from-name { font-weight: 600; font-size: 0.875rem; }
.message-from-email { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.1rem; }
.message-date { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.message-actions { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.message-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; font-size: 0.875rem; line-height: 1.75; color: var(--text); overflow-x: hidden; }
.message-body .email-html { color: var(--text); }
.message-body .email-html a { color: var(--accent); }
/* Newsletter/marketing HTML mail is routinely built as fixed-width tables
   (width="600" or similar, via attribute or inline style) that sanitize_html()
   deliberately leaves alone — those are legitimate layout, not something to
   strip. On a narrow phone screen that fixed width otherwise blows out past
   the message card and forces the whole page to scroll sideways. max-width
   on the wrapper + a contained horizontal scrollbar keeps the email's own
   layout intact (nothing gets visually squished/broken) while stopping it
   from taking the rest of the page with it; images are safe to actually
   shrink since a smaller image never breaks an email's intent the way a
   squished multi-column table would. */
.message-body .email-html { max-width: 100%; overflow-x: auto; }
.message-body .email-html img { max-width: 100%; height: auto; }
.message-body .email-html table { max-width: 100%; }
/* js/msgview.js kutistaa tämän kehyksen (transform: scale) silloin kun
   sähköpostin oma kiinteä leveys ei mahdu ruudulle — vasen yläkulma on
   ainoa kiinnityspiste, joka pitää tekstin reunassa kiinni skaalatessa. */
.message-body .email-html-inner { transform-origin: top left; }
.message-body pre { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; font-family: inherit; color: var(--text-muted); }
.attachments { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.5rem; margin-top: 1rem; }
.attachments h4 { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.75rem; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attachment-item { display: flex; align-items: center; gap: 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; font-size: 0.78rem; color: var(--text-muted); transition: border-color 0.15s, color 0.15s; max-width: 100%; min-width: 0; }
.attachment-item:hover { border-color: var(--accent); color: var(--accent); }
/* Pitkä tiedostonimi levitti liitepainikkeen kapean puhelinruudun yli. Ikoni ja
   koko pysyvät aina näkyvissä, nimi lyhenee kolmella pisteellä. */
.attachment-item > svg { flex-shrink: 0; }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.attachment-size { flex-shrink: 0; color: var(--text-muted); }

/* ===== COMPOSE ===== */
.compose-wrap { padding: 1.25rem; max-width: 860px; margin: 0 auto; }
.compose-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; }
.compose-header { padding: 0.875rem 1.5rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.9rem; color: var(--text-muted); }
.compose-field { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.compose-label { padding: 0.75rem 1rem 0.75rem 1.5rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); width: 80px; flex-shrink: 0; text-transform: uppercase; }
.compose-field input { flex: 1; padding: 0.75rem 1rem; border: none; outline: none; font-size: 0.875rem; font-family: inherit; background: transparent; color: var(--text); }
.compose-body { padding: 1rem 1.5rem; }
.compose-body textarea { width: 100%; border: none; outline: none; font-size: 0.875rem; font-family: inherit; resize: vertical; min-height: 320px; line-height: 1.7; background: transparent; color: var(--text); }
.compose-footer { padding: 0.75rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; align-items: center; }
.btn-send { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0.6rem 1.25rem; font-size: 0.85rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; font-family: inherit; transition: background 0.2s; }
.btn-send:hover { background: var(--accent-hover); }
/* Lähetä-kuvake compose-näkymän ylälaidassa — sama toiminto kuin alalaidan
   Lähetä, mutta aina näkyvissä ilman vieritystä. Täytetty korostusvärillä,
   jotta se erottuu topbarin muista ääriviivanapeista. */
.compose-send-top { background: var(--accent); border-color: var(--accent); color: #fff; padding: 0.45rem 0.6rem; }
.compose-send-top:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.compose-send-top:disabled { opacity: 0.6; cursor: default; }
.compose-sched-top { color: var(--accent); border-color: var(--accent); padding: 0.45rem 0.6rem; }
.compose-sched-top:hover { background: rgba(59,130,246,0.12); color: var(--accent); border-color: var(--accent); }
.compose-sched-top:disabled { opacity: 0.6; cursor: default; }
/* Kapealla ruudulla alapalkki rivittyy, ja lähettäjäosoite lyhenee ellipsillä
   sen sijaan että valuisi kortin reunan yli. */
.compose-footer { flex-wrap: wrap; row-gap: 0.5rem; }
.compose-footer > span:last-child, .compose-footer .from-switcher { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Lainauksen näytä/piilota (vastaus & välitys) */
.quote-toggle-row { padding: 0 1.5rem 0.75rem; }
.quote-toggle-btn { background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); font-family: inherit; font-size: 0.75rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.7rem; transition: border-color 0.15s, color 0.15s; }
.quote-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.quote-toggle-btn .quote-dots { letter-spacing: 0.1em; line-height: 1; }
/* Palautetun luonnoksen ilmoitus editorin yläpuolella */
.draft-banner { display: flex; align-items: center; gap: 0.75rem; margin: 0 1.5rem 0.6rem; padding: 0.5rem 0.75rem; border: 1px solid rgba(59,130,246,0.3); background: rgba(59,130,246,0.1); border-radius: 8px; color: var(--text-muted); font-size: 0.78rem; }
.draft-banner-btn { margin-left: auto; background: none; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); font-family: inherit; font-size: 0.72rem; cursor: pointer; padding: 0.2rem 0.6rem; }
.draft-banner-btn:hover { border-color: #f87171; color: #f87171; }
.btn-discard { background: none; border: none; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; font-family: inherit; }
.btn-discard:hover { color: #f87171; }
/* Ajastettu lähetys (compose.php) */
.sched-wrap { position: relative; }
.btn-sched { background: none; border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); width: 36px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.btn-sched:hover { color: var(--accent); border-color: var(--accent); }
.sched-menu { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; width: 290px; max-width: calc(100vw - 2rem); box-shadow: 0 6px 24px rgba(0,0,0,0.45); z-index: 100; overflow: hidden; }
.sched-title { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 0.7rem 0.9rem 0.35rem; }
.sched-custom { padding: 0.2rem 0.9rem 0.85rem; display: flex; flex-direction: column; gap: 0.45rem; }
.sched-custom label { font-size: 0.74rem; color: var(--text-muted); }
.sched-custom input { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 0.45rem 0.55rem; font: inherit; font-size: 0.82rem; color-scheme: dark; }
.sched-go { justify-content: center; padding: 0.5rem 1rem; }
[data-theme="light"] .sched-custom input { color-scheme: light; }
.from-switcher { font-size: 0.72rem; }
.from-switcher-btn { background: none; border: none; color: var(--text-muted); font-size: 0.72rem; cursor: pointer; display: flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.4rem; border-radius: 5px; font-family: inherit; transition: background 0.15s, color 0.15s; }
.from-switcher-btn:hover { background: rgba(59,130,246,0.1); color: var(--accent); }
.from-dropdown { position: absolute; bottom: calc(100% + 4px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 220px; box-shadow: 0 4px 20px rgba(0,0,0,0.4); z-index: 100; overflow: hidden; }
.from-option { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: none; color: var(--text); font-size: 0.8rem; padding: 0.6rem 0.9rem; cursor: pointer; font-family: inherit; text-align: left; transition: background 0.12s; }
.from-option:hover { background: rgba(255,255,255,0.05); }
.from-option.active { color: var(--accent); }
.flash { padding: 0.75rem 1.25rem; font-size: 0.85rem; font-weight: 500; border-bottom: 1px solid var(--border); }
.flash.success { background: rgba(34,197,94,0.08); color: #4ade80; }
.flash.error { background: rgba(220,38,38,0.08); color: #f87171; }

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40; }

/* ===== SETTINGS ===== */
.settings-wrap { padding: 1.25rem; max-width: 620px; display: flex; flex-direction: column; gap: 1rem; }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.settings-card-title { display: flex; align-items: center; gap: 0.5rem; padding: 0.875rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.875rem; color: var(--text-muted); }
.settings-row { display: flex; align-items: center; padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--border); gap: 1rem; }
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 0.8rem; color: var(--text-muted); width: 140px; flex-shrink: 0; }
.settings-value { font-size: 0.875rem; color: var(--text); }
.settings-form-row { padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--border); }
.settings-form-row label { display: block; font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.settings-form-row input { width: 100%; padding: 0.6rem 0.875rem; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 7px; color: var(--text); font-size: 0.875rem; font-family: inherit; }
.settings-form-row input[type=checkbox],
.settings-form-row input[type=radio] { width: auto; padding: 0; min-height: 0; background: none; border: none; flex-shrink: 0; }
.settings-form-row input:focus { outline: none; border-color: var(--accent); }
.settings-form-row textarea { width: 100%; padding: 0.6rem 0.875rem; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 7px; color: var(--text); font-size: 0.875rem; font-family: inherit; resize: vertical; min-height: 100px; line-height: 1.6; }
.settings-form-row textarea:focus { outline: none; border-color: var(--accent); }
.field-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem; }
.settings-card > div:last-child:not(.settings-card-title):not(.settings-form-row):not(.settings-row) { padding: 0.875rem 1.25rem; }
.settings-form-section-label { padding: 0.55rem 1.25rem 0.15rem; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--accent); border-top: 1px solid var(--border); }
.settings-form-row-2 { display: flex; gap: 0; }
.settings-form-row-2 .settings-form-row { flex: 1; }
.settings-form-row-2 .settings-form-row:last-child { border-left: 1px solid var(--border); }
.lang-options { display: flex; gap: 0.75rem; margin-top: 0.3rem; }
.lang-option { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1.5px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 0.875rem; transition: border-color 0.15s, background 0.15s; }
.lang-option input[type="radio"] { display: none; }
.lang-option.active, .lang-option:has(input:checked) { border-color: var(--accent); background: rgba(59,130,246,0.08); color: var(--accent); font-weight: 600; }
.lang-option:hover { border-color: var(--accent); }
.lang-flag { font-size: 1.1rem; }

/* ===== AVATAR ===== */
.avatar-section { display: flex; align-items: flex-start; gap: 1.5rem; padding: 1.25rem; }
.avatar-preview img { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); display: block; }
.avatar-actions { flex: 1; }
.avatar-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.5rem; line-height: 1.4; }
.btn-danger-sm { background: none; border: 1px solid rgba(248,113,113,0.3); color: #f87171; border-radius: 7px; padding: 0.4rem 0.75rem; font-size: 0.78rem; cursor: pointer; font-family: inherit; transition: background 0.15s; margin-top: 0.5rem; display: inline-block; text-decoration: none; }
.btn-danger-sm:hover { background: rgba(248,113,113,0.08); }

/* ===== COMPOSE TOOLBAR ===== */
.compose-toolbar { padding: 0.5rem 1.25rem; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; background: rgba(255,255,255,0.02); }
.toolbar-btn { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; color: var(--text-muted); cursor: pointer; border: none; background: none; border-radius: 6px; padding: 0.45rem 0.7rem; transition: background 0.13s, color 0.13s; font-family: inherit; white-space: nowrap; min-height: 38px; }
.toolbar-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.toolbar-btn-img { color: var(--accent2); }
.toolbar-btn-img:hover { background: rgba(6,182,212,0.1); color: var(--accent2); }
.toolbar-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; margin: 0 0.2rem; }
.toolbar-fmt { font-weight: 800; min-width: 26px; justify-content: center; padding: 0.3rem 0.35rem; }
.toolbar-fmt.active { color: var(--accent); background: rgba(59,130,246,0.18); border-radius: 5px; }
.toolbar-color-btn { flex-direction: column; gap: 2px; padding: 0.2rem 0.4rem; min-width: 22px; }
.color-letter { font-size: 0.82rem; font-weight: 800; line-height: 1; }
.color-bar { display: block; width: 14px; height: 3px; border-radius: 1px; }
.toolbar-dd-wrap { position: relative; display: inline-flex; }
.toolbar-dd-btn { gap: 0.25rem; justify-content: space-between; min-width: 64px; }
.toolbar-dd-menu { position: absolute; top: calc(100% + 4px); left: 0; background: var(--surface,#111827); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; min-width: 150px; z-index: 200; box-shadow: 0 6px 24px rgba(0,0,0,0.5); overflow: hidden; }
.toolbar-dd-item { display: block; width: 100%; background: none; border: none; color: var(--text,#f8fafc); font-size: 0.8rem; padding: 0.45rem 0.85rem; cursor: pointer; font-family: inherit; text-align: left; transition: background 0.12s; white-space: nowrap; }
.toolbar-dd-item:hover { background: rgba(59,130,246,0.1); color: var(--accent,#3b82f6); }
.toolbar-dd-search-wrap { position: sticky; top: 0; background: var(--surface,#111827); z-index: 1; padding: 0.4rem; border-bottom: 1px solid var(--border); }
.toolbar-dd-search { width: 100%; background: var(--bg2,#0d1830); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 0.3rem 0.55rem; font-size: 0.78rem; font-family: inherit; outline: none; }
.toolbar-dd-search:focus { border-color: var(--accent); }
.file-list { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
/* Sama kuin .attachment-name: pitkä nimi ei saa venyttää chippiä ruudun yli. */
.file-chip { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.2); color: var(--accent); border-radius: 20px; padding: 0.2rem 0.65rem; font-size: 0.72rem; max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== LINK PANEL ===== */
.link-panel { border-top: 1px solid var(--border); padding: 0.75rem 1.25rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; background: rgba(59,130,246,0.04); }
.link-panel-input { flex: 1; min-width: 160px; background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: 0.4rem 0.75rem; font-size: 0.85rem; font-family: inherit; }
.link-panel-input:focus { outline: none; border-color: var(--accent); }

/* ===== COMPOSE EDITOR ===== */
.compose-editor {
    min-height: 280px;
    padding: 1.1rem 1.5rem;
    color: var(--text);
    font-size: 0.94rem;
    line-height: 1.75;
    outline: none;
    border: none;
    white-space: pre-wrap;
    word-break: break-word;
}
.compose-editor p { margin: 0; }
.compose-editor img { max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 4px 0; cursor: default; }
.compose-editor a { color: var(--accent); }
.compose-editor blockquote { border-left: 3px solid var(--accent); margin: 0; padding-left: 1rem; color: var(--text-muted); }
/* Placeholder */
.compose-editor { position: relative; }
.compose-editor[data-empty="true"]:before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
    position: absolute;
    top: 1.1rem;
    left: 1.5rem;
}

/* ===== RESPONSIVE ===== */
/* ===== PAGE LOADING INDICATOR ===== */
#page-loader { position:fixed; top:0; left:0; right:0; height:2px; background:var(--accent); z-index:10000; transform:scaleX(0); transform-origin:left; transition:transform 0.3s ease; }
#page-loader.active { transform:scaleX(0.7); transition:transform 2s ease-out; }
#page-loader.done  { transform:scaleX(1); opacity:0; transition:transform 0.15s, opacity 0.3s 0.15s; }
#nav-spinner { display:flex; position:fixed; inset:0; z-index:9999; background:rgba(6,12,26,0.5); backdrop-filter:blur(2px); align-items:center; justify-content:center; opacity:0; pointer-events:none; transition:opacity 0.12s; }
#nav-spinner.active { opacity:1; pointer-events:all; }
#nav-spinner-circle { width:40px; height:40px; border:3px solid rgba(255,255,255,0.1); border-top-color:var(--accent,#3b82f6); border-radius:50%; animation:nav-spin 0.75s linear infinite; }
@keyframes nav-spin { to { transform:rotate(360deg); } }

/* Viestinäkymän yläpalkki: pelkät kuvakkeet kun tekstit eivät mahdu yhdelle
   riville (sivupalkki vie tabletilla tilaa). Nimet title/aria-labelissa (message.php). */
@media (max-width: 1100px) {
    .msg-topbar-actions .btn-icon span, .msg-back-btn span { display: none; }
    .msg-topbar-actions { gap: 0.35rem; }
    .msg-topbar-actions .btn-icon, .msg-back-btn { padding: 0.45rem 0.55rem; }
}

@media (max-width: 768px) {
    /* Saapumisaika omalle rivilleen lähettäjän alle */
    .message-meta { flex-wrap: wrap; }
    .message-date { flex-basis: 100%; padding-left: calc(38px + 0.75rem); margin-top: -0.25rem; }
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; transform: translateX(-100%); width: 260px; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .topbar-menu-btn { display: flex; align-items: center; justify-content: center; }
    .msg-item, .msg-item:not(:has(> .msg-date)) { grid-template-columns: 34px 1fr; }
    .msg-date { display: none; }
    .message-view, .compose-wrap { padding: 0.75rem; }
    #topbar-actions-default.topbar-actions .btn-icon span { display: none; }
    #topbar-actions-select { gap: 0.35rem; }
    #topbar-actions-select .btn-icon { padding: 0.35rem 0.5rem; font-size: 0.72rem; }
}

/* ===== TAG INPUT / TO FIELD ===== */
.compose-to-field { align-items: flex-start; position: relative; }
.to-outer { flex: 1; min-width: 0; position: relative; }
.to-wrap { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.5rem 1rem 0.5rem 0; }
.tag-input-box { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; background: transparent; padding: 0.25rem 0; min-height: 28px; cursor: text; }
.tag-chip { display: inline-flex; align-items: center; gap: 0.2rem; background: rgba(59,130,246,0.14); border: 1px solid rgba(59,130,246,0.3); color: var(--accent); border-radius: 20px; padding: 0.1rem 0.45rem 0.1rem 0.55rem; font-size: 0.75rem; white-space: nowrap; max-width: 220px; }
.tag-chip-label { overflow: hidden; text-overflow: ellipsis; }
.tag-chip-del { background: none; border: none; color: inherit; cursor: pointer; padding: 0 0 0 0.1rem; line-height: 1; font-size: 1rem; opacity: 0.65; flex-shrink: 0; }
.tag-chip-del:hover { opacity: 1; }
.tag-text { background: none; border: none; outline: none; color: var(--text); font-size: 0.875rem; min-width: 120px; flex: 1; padding: 0; font-family: inherit; line-height: 1.5; }
.contacts-pick-btn { flex-shrink: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.6rem; font-size: 0.72rem; font-family: inherit; transition: border-color 0.15s, color 0.15s; white-space: nowrap; margin-top: 0.25rem; }
.contacts-pick-btn:hover { border-color: var(--accent); color: var(--accent); }
.contacts-dd { position: absolute; top: 100%; left: 0; right: 1px; z-index: 600; background: var(--surface); border: 1px solid var(--border2); border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.55); overflow: hidden; }
.contacts-dd-top { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.contacts-sel-all-btn { background: none; border: none; color: var(--accent); font-size: 0.75rem; cursor: pointer; padding: 0; font-family: inherit; }
.contacts-sel-all-btn:hover { text-decoration: underline; }
.contacts-list { max-height: 210px; overflow-y: auto; }
.contact-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.75rem; transition: background 0.1s; }
.contact-item:hover { background: rgba(59,130,246,0.06); }
.contact-item input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; flex-shrink: 0; cursor: pointer; }
.contact-item-info { flex: 1; min-width: 0; }
.contact-item-email { font-size: 0.8rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-item-name { font-size: 0.7rem; color: var(--text-muted); }
.contact-item-del { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.15rem 0.3rem; font-size: 0.75rem; opacity: 0; transition: opacity 0.1s; flex-shrink: 0; }
.contact-item:hover .contact-item-del { opacity: 1; }
.contacts-dd-add { border-top: 1px solid var(--border); }
.contacts-add-toggle { display: flex; align-items: center; gap: 0.35rem; background: none; border: none; color: var(--text-muted); font-size: 0.75rem; padding: 0.5rem 0.75rem; cursor: pointer; font-family: inherit; width: 100%; }
.contacts-add-toggle:hover { color: var(--accent); }
.contacts-add-input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 0.35rem 0.6rem; font-size: 0.78rem; font-family: inherit; outline: none; }
.contacts-add-input:focus { border-color: var(--accent); }
.contacts-dd-footer { display: flex; gap: 0.5rem; padding: 0.5rem 0.75rem; border-top: 1px solid var(--border); }
.contacts-empty { padding: 1rem 0.75rem; text-align: center; color: var(--text-muted); font-size: 0.78rem; line-height: 1.6; }
.save-to-contacts-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 1rem 0.3rem 0; }
.save-cb-label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; color: var(--text-muted); cursor: pointer; white-space: nowrap; user-select: none; }
.save-cb-label input[type=checkbox] { accent-color: var(--accent); width: 13px; height: 13px; cursor: pointer; }
.save-cb-label:hover { color: var(--text); }
.save-contact-name-input { flex: 1; min-width: 0; background: transparent; border: none; border-bottom: 1px solid var(--border); outline: none; color: var(--text); font-size: 0.78rem; font-family: inherit; padding: 0.15rem 0.3rem; }
.save-contact-name-input:focus { border-bottom-color: var(--accent); }
.contact-item-edit { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.15rem 0.3rem; font-size: 0.8rem; opacity: 0; transition: opacity 0.1s; flex-shrink: 0; }
.contact-item:hover .contact-item-edit { opacity: 1; }
.contact-edit-form { padding: 0.5rem 0.75rem; }

/* =====================
   PHOTOSHOP-STYLE COLOR PICKER (shared — js/colorpicker.js)
   ===================== */
.cp-popup { position:fixed; z-index:10010; background:#131e33; border:1px solid rgba(255,255,255,0.12); border-radius:12px; width:222px; max-height:calc(100vh - 16px); box-shadow:0 14px 44px rgba(0,0,0,0.75); overflow-y:auto; overflow-x:hidden; user-select:none; touch-action:pan-y; }
.cp-sq { position:relative; width:222px; height:148px; cursor:crosshair; flex-shrink:0; }
.cp-sq-sat { position:absolute; inset:0; background:linear-gradient(to right, #fff, transparent); }
.cp-sq-bri { position:absolute; inset:0; background:linear-gradient(to bottom, transparent, #000); }
.cp-sq-dot { position:absolute; width:12px; height:12px; border:2px solid #fff; border-radius:50%; transform:translate(-50%,-50%); pointer-events:none; box-shadow:0 0 0 1.5px rgba(0,0,0,0.5); }
.cp-row2 { display:flex; align-items:center; gap:8px; padding:8px 10px 6px; }
.cp-thumb-swatch { width:26px; height:26px; border-radius:50%; flex-shrink:0; position:relative; overflow:hidden; border:2px solid rgba(255,255,255,0.18); }
.cp-thumb-check { position:absolute; inset:0; background-image:linear-gradient(45deg,#555 25%,transparent 25%),linear-gradient(-45deg,#555 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#555 75%),linear-gradient(-45deg,transparent 75%,#555 75%); background-size:6px 6px; background-position:0 0,0 3px,3px -3px,-3px 0; }
.cp-thumb-fill { position:absolute; inset:0; }
.cp-sliders { flex:1; display:flex; flex-direction:column; gap:6px; }
.cp-hue-track { position:relative; height:10px; border-radius:5px; background:linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); cursor:pointer; }
.cp-alp-track { position:relative; height:10px; border-radius:5px; cursor:pointer; overflow:hidden; }
.cp-alp-check { position:absolute; inset:0; background-image:linear-gradient(45deg,#777 25%,transparent 25%),linear-gradient(-45deg,#777 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#777 75%),linear-gradient(-45deg,transparent 75%,#777 75%); background-size:6px 6px; background-position:0 0,0 3px,3px -3px,-3px 0; }
.cp-alp-grad { position:absolute; inset:0; }
.cp-slide-thumb { position:absolute; top:50%; width:14px; height:14px; background:#fff; border-radius:50%; transform:translate(-50%,-50%); box-shadow:0 0 0 1.5px rgba(0,0,0,0.45); pointer-events:none; }
.cp-inputs { display:flex; align-items:center; gap:3px; padding:0 10px 6px; }
.cp-hash,.cp-alabel,.cp-pct { font-size:0.68rem; color:rgba(255,255,255,0.38); flex-shrink:0; }
.cp-hexin { flex:1; min-width:0; background:#0d1626; border:1px solid rgba(255,255,255,0.1); color:#e2e8f0; border-radius:5px; padding:3px 5px; font-size:0.75rem; font-family:monospace; }
.cp-anumIn { width:34px; background:#0d1626; border:1px solid rgba(255,255,255,0.1); color:#e2e8f0; border-radius:5px; padding:3px 3px; font-size:0.75rem; font-family:monospace; text-align:center; -moz-appearance:textfield; }
.cp-anumIn::-webkit-inner-spin-button { display:none; }
.cp-hexin:focus,.cp-anumIn:focus { outline:none; border-color:var(--accent,#3b82f6); }
.cp-saved { display:flex; flex-wrap:wrap; gap:4px; padding:0 10px 8px; min-height:10px; }
.cp-sw { width:17px; height:17px; border-radius:3px; cursor:pointer; border:1.5px solid rgba(255,255,255,0.15); flex-shrink:0; transition:transform 0.1s; }
.cp-sw:hover { transform:scale(1.2); }
.cp-actions { display:flex; gap:5px; padding:0 10px 10px; justify-content:flex-end; }
.cp-btn { font-size:0.7rem; padding:3px 10px; border-radius:6px; border:1px solid rgba(255,255,255,0.12); cursor:pointer; background:#0d1626; color:#e2e8f0; }
.cp-btn.primary { background:var(--accent,#3b82f6); border-color:transparent; color:#fff; }

/* =====================
   RICH-TEXT SIGNATURE / VACATION EDITOR (shared — settings.php + demo)
   ===================== */
.sig-toolbar { display:flex; gap:0.3rem; align-items:center; margin-top:0.4rem; margin-bottom:0.3rem; flex-wrap:wrap; }
.sig-editor { min-height:80px; padding:0.6rem 0.875rem; background:var(--bg2); border:1.5px solid var(--border); border-radius:7px; color:var(--text); font-size:0.875rem; font-family:inherit; line-height:1.6; outline:none; }
.sig-editor:focus { border-color:var(--accent); }
.sig-editor a { color:var(--accent); text-decoration:underline; }
.sig-link-panel { display:flex; gap:0.5rem; align-items:center; flex-wrap:wrap; background:rgba(59,130,246,0.04); border:1px solid var(--border); border-radius:7px; padding:0.5rem 0.75rem; margin-bottom:0.3rem; }
.sig-link-input { flex:1; min-width:120px; background:var(--surface2,#1a2540); border:1px solid var(--border); color:var(--text); border-radius:6px; padding:0.35rem 0.6rem; font-size:0.82rem; font-family:inherit; }
.sig-link-input:focus { outline:none; border-color:var(--accent); }
@media(max-width:640px) {
  .sig-toolbar { flex-wrap:nowrap; overflow-x:auto; -webkit-overflow-scrolling:touch; scrollbar-width:none; padding-bottom:2px; }
  .sig-toolbar::-webkit-scrollbar { display:none; }
  .sig-toolbar .toolbar-btn { padding:0.35rem 0.55rem; min-height:34px; font-size:0.82rem; flex-shrink:0; }
  .sig-toolbar .toolbar-sep { flex-shrink:0; }
  .sig-toolbar .toolbar-dd-wrap { flex-shrink:0; }
}
/* Vacation card overrides */
.vac-check-label { display:flex !important; align-items:center; gap:0.75rem; cursor:pointer; font-size:0.9rem !important; font-weight:400 !important; color:var(--text) !important; text-transform:none !important; letter-spacing:0 !important; margin-bottom:0 !important; flex-wrap:wrap; }
.vac-check-label .vac-check-text strong { color: var(--accent); font-weight: 600; }

/* Custom toggle switch (replaces the plain native checkbox for the vacation on/off) */
.vac-switch { position: relative; display: inline-block; width: 40px; height: 23px; flex-shrink: 0; }
.vac-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.vac-switch-track { position: absolute; inset: 0; background: var(--bg2); border: 1.5px solid var(--border); border-radius: 999px; transition: background 0.2s, border-color 0.2s; pointer-events: none; }
.vac-switch-track::before { content: ""; position: absolute; height: 15px; width: 15px; left: 3px; top: 50%; transform: translateY(-50%); background: var(--text-muted); border-radius: 50%; transition: transform 0.2s, background 0.2s; }
.vac-switch input:checked + .vac-switch-track { background: var(--accent); border-color: var(--accent); }
.vac-switch input:checked + .vac-switch-track::before { transform: translate(17px, -50%); background: #fff; }
.vac-switch input:focus-visible + .vac-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.vac-radio-group { display:flex; gap:0.5rem; flex-wrap:wrap; }
.vac-radio-label { display:inline-flex !important; align-items:center; gap:0.4rem; cursor:pointer; font-size:0.85rem !important; font-weight:500 !important; color:var(--text-muted) !important; text-transform:none !important; letter-spacing:0 !important; margin-bottom:0 !important; white-space:nowrap; padding:0.4rem 0.85rem; border-radius:999px; border:1.5px solid var(--border); background:var(--bg2); transition:background 0.15s, border-color 0.15s, color 0.15s; position:relative; }
.vac-radio-label input[type=radio] { position:absolute; opacity:0; width:0; height:0; pointer-events:none; margin:0; }
.vac-radio-label:has(input:checked) { background:var(--accent); border-color:var(--accent); color:#fff !important; }

/* ===== KUVAN MUOKKAUS EDITORISSA (js/imgedit.js) ===== */
/* Kahvat piirretään erilliseen overlayhin eikä kuvan sisään: kuva on
   contenteditablen sisällä, jonne lisätyt elementit menisivät mukaan viestiin
   ja sekoittuisivat tekstin muokkaukseen. */
.compose-editor img, .sig-editor img { cursor: pointer; }
img.imged-selected { outline: none; }

/* absolute eikä fixed: puhelimen näppäimistö siirtää visuaalista näkymäikkunaa
   layout-ikkunan sisällä, jolloin fixed-kehys jäisi kuvan viereen. Ks. position()
   js/imgedit.js:ssä. */
.imged-ov {
    position: absolute;
    z-index: 10020;
    display: none;
    pointer-events: none;
}
.imged-ov[data-mode="crop"] { overflow: hidden; }

.imged-frame {
    position: absolute;
    left: 0; top: 0; width: 100%; height: 100%;
    border: 1.5px solid var(--accent, #3b82f6);
    box-sizing: border-box;
    pointer-events: none;
}
/* Rajaustilassa rajauksen ulkopuoli himmennetään. box-shadow kattaa koko
   overlayn, joka leikkaa ylimenevän (overflow:hidden yllä). */
.imged-ov[data-mode="crop"] .imged-frame {
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    border-style: dashed;
}

.imged-h {
    position: absolute;
    width: 11px; height: 11px;
    margin: -6px 0 0 -6px;
    background: #fff;
    border: 1.5px solid var(--accent, #3b82f6);
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: auto;
    touch-action: none;
}
.imged-h-nw { left: 0;    top: 0;    cursor: nwse-resize; }
.imged-h-n  { left: 50%;  top: 0;    cursor: ns-resize; }
.imged-h-ne { left: 100%; top: 0;    cursor: nesw-resize; }
.imged-h-e  { left: 100%; top: 50%;  cursor: ew-resize; }
.imged-h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.imged-h-s  { left: 50%;  top: 100%; cursor: ns-resize; }
.imged-h-sw { left: 0;    top: 100%; cursor: nesw-resize; }
.imged-h-w  { left: 0;    top: 50%;  cursor: ew-resize; }

/* Kääntökahva: viiva yläreunan keskeltä ylös ja pallo sen päässä. */
.imged-rotline {
    position: absolute;
    left: 50%; top: -26px;
    width: 1.5px; height: 26px;
    margin-left: -0.75px;
    background: var(--accent, #3b82f6);
    pointer-events: none;
}
.imged-rot {
    position: absolute;
    left: 50%; top: -32px;
    width: 13px; height: 13px;
    margin: -6.5px 0 0 -6.5px;
    background: var(--accent, #3b82f6);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    cursor: grab;
    pointer-events: auto;
    touch-action: none;
}
.imged-ov.imged-dragging .imged-rot { cursor: grabbing; }

.imged-bar {
    position: absolute;
    left: 50%; top: 100%;
    transform: translate(-50%, 10px);
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--surface, #111827);
    border: 1px solid var(--border, rgba(255,255,255,0.08));
    border-radius: 8px;
    box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.3));
    pointer-events: auto;
    white-space: nowrap;
}
.imged-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    background: none;
    border: none;
    border-radius: 5px;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    padding: 0;
}
.imged-btn:hover { color: var(--text, #f8fafc); background: rgba(127,127,127,0.16); }
.imged-btn.active { color: var(--accent, #3b82f6); background: rgba(59,130,246,0.18); }

/* Kosketuslaitteella kahvat ovat isommat, jotta niihin osuu sormella. Näkyvän
   pallon lisäksi kahvalla on näkymätön kosketusalue: ::before ei voi olla
   tapahtuman kohde, joten data-dir luetaan yhä itse kahvasta. */
@media (hover: none) and (pointer: coarse) {
    .imged-h { width: 15px; height: 15px; margin: -8px 0 0 -8px; }
    .imged-rot { width: 17px; height: 17px; margin: -8.5px 0 0 -8.5px; }
    .imged-btn { width: 32px; height: 32px; }
    .imged-h::before, .imged-rot::before {
        content: '';
        position: absolute;
        left: -11px; top: -11px; right: -11px; bottom: -11px;
    }
}
