* { box-sizing: border-box; }
:root {
    --bg: #ececf1;
    --card: #ffffff;
    --line: #e8e8ee;
    --text: #111111;
    --muted: #72727a;
    --icon: #121212;
    --blue: #0a84ff;
    --green: #16a34a;
    --zalo: #0068ff;
    --danger: #dc2626;
    --soft: #f6f6f9;
    --shadow: 0 18px 40px rgba(17, 24, 39, .08);
    --radius: 28px;
    --radius-sm: 18px;
    --radius-xs: 14px;
    --font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
html, body { margin: 0; min-height: 100%; background: linear-gradient(180deg, #f5f5f8, #ececf1); font-family: var(--font); color: var(--text); }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.phone-shell { min-height: 100vh; display: flex; justify-content: center; align-items: stretch; padding: 0; }
.app-frame {
    width: min(100vw, 520px);
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    box-shadow: 0 0 0 1px rgba(0,0,0,.03), var(--shadow);
}
.app-header { padding: max(18px, env(safe-area-inset-top)) 22px 16px; }
.app-header__top { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; min-height: 140px; }
.app-header h1 { margin: 0; font-size: clamp(44px, 8vw, 58px); line-height: .95; font-weight: 800; letter-spacing: -.04em; }
.app-header p { margin: 10px 0 0; color: var(--muted); font-size: 16px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; }
.toolbar-btn {
    width: 46px; height: 46px; border: 0; background: transparent; border-radius: 50%;
    display: grid; place-items: center; color: var(--icon); font-size: 32px; cursor: pointer;
}
.toolbar-btn:hover { background: rgba(0,0,0,.04); }
.icon-search, .icon-dots, .icon-grid, .icon-recent, .icon-person, .icon-phone, .icon-sms, .icon-copy, .icon-edit, .icon-delete, .icon-share, .icon-zalo-chat, .icon-zalo-call { display: inline-block; }
.icon-search { width: 22px; height: 22px; border: 3px solid currentColor; border-radius: 50%; position: relative; }
.icon-search::after { content: ''; position: absolute; width: 10px; height: 3px; background: currentColor; border-radius: 3px; right: -8px; bottom: -4px; transform: rotate(45deg); }
.icon-dots { width: 4px; height: 18px; background: currentColor; border-radius: 999px; position: relative; }
.icon-dots::before, .icon-dots::after { content: ''; position: absolute; left: 0; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.icon-dots::before { top: -7px; }
.icon-dots::after { bottom: -7px; }
.search-panel { margin-top: 12px; background: rgba(255,255,255,.76); border-radius: 24px; padding: 12px; border: 1px solid rgba(255,255,255,.7); }
.search-box { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 18px; padding: 0 14px; min-height: 52px; }
.search-box input { border: 0; background: transparent; width: 100%; outline: none; font-size: 16px; }
.clear-input { border: 0; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; color: #80808a; }
.compact-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.compact-filters label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.compact-filters select { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 14px; padding: 0 12px; background: #fff; }
.app-main { padding: 0 16px 92px; }
.section-block { margin-bottom: 14px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 6px 10px; }
.section-title-row h2 { margin: 0; font-size: 18px; }
.text-btn { border: 0; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.contact-list, .alpha-group { background: var(--card); border-radius: 26px; overflow: hidden; box-shadow: 0 1px 0 rgba(0,0,0,.02); }
.compact-list .contact-row:last-child, #contacts-list .contact-row:last-child { border-bottom: 0; }
.contact-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 0 4px; border-bottom: 1px solid var(--line); min-height: 82px; }
.contact-main { flex: 1; border: 0; background: transparent; display: flex; align-items: center; gap: 14px; padding: 14px 12px; text-align: left; cursor: pointer; }
.contact-side { display: flex; align-items: center; gap: 4px; }
.avatar {
    width: 50px; height: 50px; border-radius: 50%; flex: 0 0 50px; display: grid; place-items: center;
    font-size: 24px; color: #fff; font-weight: 700; background: linear-gradient(135deg, #80d8ff, #a78bfa);
}
.contact-copy { min-width: 0; }
.contact-name { font-size: 18px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-meta { margin-top: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star-btn, .more-btn {
    width: 42px; height: 42px; border: 0; background: transparent; border-radius: 50%; cursor: pointer;
    display: grid; place-items: center; color: #70707a; font-size: 24px;
}
.star-btn.is-active { color: #f59e0b; }
.star-btn:hover, .more-btn:hover { background: rgba(0,0,0,.04); }
.alpha-label { padding: 10px 16px 8px; font-size: 13px; font-weight: 800; color: var(--muted); letter-spacing: .14em; }
.empty-box { background: rgba(255,255,255,.7); border-radius: 22px; padding: 18px; text-align: center; color: var(--muted); }
.bottom-nav {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100vw, 520px);
    background: rgba(244,244,247,.92); backdrop-filter: blur(14px); border-top: 1px solid rgba(0,0,0,.06);
    display: grid; grid-template-columns: repeat(3, 1fr); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); z-index: 12;
}
.tab-btn { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 6px; color: #787880; cursor: pointer; padding: 8px 6px; }
.tab-btn.is-active { color: var(--text); font-weight: 700; }
.tab-icon { width: 22px; height: 22px; position: relative; }
.icon-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.icon-grid::before, .icon-grid::after { content: ''; }
.icon-grid, .icon-grid::before, .icon-grid::after { background: transparent; }
.icon-grid { box-shadow: inset 0 0 0 2px currentColor; border-radius: 6px; }
.icon-grid::before { position: absolute; inset: 4px 8px; border-left: 2px solid currentColor; border-right: 2px solid currentColor; }
.icon-grid::after { position: absolute; inset: 8px 4px; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; }
.icon-recent::before { content: ''; position: absolute; inset: 1px; border: 2px solid currentColor; border-radius: 50%; }
.icon-recent::after { content: ''; position: absolute; width: 8px; height: 2px; background: currentColor; top: 6px; left: 10px; transform-origin: left center; transform: rotate(45deg); box-shadow: -5px 5px 0 0 currentColor; }
.icon-person::before { content: ''; position: absolute; width: 10px; height: 10px; border-radius: 50%; background: currentColor; top: 1px; left: 6px; }
.icon-person::after { content: ''; position: absolute; width: 18px; height: 10px; border-radius: 10px 10px 6px 6px; background: currentColor; bottom: 1px; left: 2px; }
.menu-panel {
    position: fixed; top: 118px; right: calc(50% - min(50vw, 260px) + 16px); z-index: 40; background: #fff;
    border-radius: 20px; box-shadow: 0 18px 44px rgba(0,0,0,.18); padding: 8px; min-width: 220px;
}
.menu-item { width: 100%; border: 0; background: transparent; display: block; text-align: left; padding: 12px 14px; border-radius: 14px; cursor: pointer; }
.menu-item:hover { background: rgba(0,0,0,.04); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 30; }
.sheet {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100vw, 520px); background: #fff;
    border-radius: 28px 28px 0 0; box-shadow: 0 -20px 40px rgba(0,0,0,.15); z-index: 50; padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet__handle { width: 46px; height: 5px; border-radius: 999px; background: #d4d4d8; margin: 4px auto 12px; }
.sheet__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet__title { font-size: 20px; font-weight: 700; }
.sheet__subtitle { margin-top: 4px; color: var(--muted); font-size: 14px; }
.sheet__close { border: 0; background: #f4f4f5; width: 36px; height: 36px; border-radius: 50%; font-size: 28px; line-height: 1; cursor: pointer; }
.sheet__actions { margin-top: 14px; display: grid; gap: 8px; }
.action-btn {
    width: 100%; border: 0; background: #f8f8fb; min-height: 60px; border-radius: 18px; display: flex; align-items: center; gap: 14px; padding: 0 14px; cursor: pointer; text-align: left;
}
.action-btn[aria-disabled="true"] { opacity: .5; }
.action-btn__icon {
    width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 40px; color: #fff;
}
.action-btn__text strong { display: block; font-size: 15px; }
.action-btn__text span { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.action-btn--phone .action-btn__icon { background: var(--green); }
.action-btn--sms .action-btn__icon { background: var(--blue); }
.action-btn--copy .action-btn__icon { background: #64748b; }
.action-btn--edit .action-btn__icon { background: #7c3aed; }
.action-btn--delete .action-btn__icon { background: var(--danger); }
.action-btn--zalo-chat .action-btn__icon, .action-btn--zalo-call .action-btn__icon { background: var(--zalo); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.26); display: grid; place-items: center; z-index: 60; padding: 18px; }
.modal-card { width: min(100%, 520px); background: #fff; border-radius: 28px; padding: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.2); }
.small-modal { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 8px; }
.form-field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.form-field input, .form-field textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 16px; padding: 13px 14px; outline: none; background: #fff;
}
.form-field textarea { resize: vertical; }
.form-field.full { grid-column: 1 / -1; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.spacer { flex: 1; }
.primary-btn, .ghost-btn, .mini-action { border: 0; border-radius: 16px; min-height: 48px; padding: 0 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.primary-btn, .mini-action { background: var(--text); color: #fff; }
.ghost-btn, .mini-action--ghost { background: #f4f4f5; color: var(--text); }
.danger-btn { color: var(--danger); }
.hint-text { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.dialer-card { background: #fff; border-radius: 28px; padding: 16px; }
.dialer-display { min-height: 64px; display: flex; align-items: center; justify-content: center; font-size: 34px; letter-spacing: .04em; font-weight: 500; }
.dialer-actions, .dialer-footer { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dialer-footer { grid-template-columns: repeat(2, 1fr); margin-top: 10px; }
.dial-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.dial-key { aspect-ratio: 1 / 1; border-radius: 50%; border: 0; background: #f5f5f5; display: grid; place-items: center; cursor: pointer; }
.dial-key strong { font-size: 28px; line-height: 1; }
.dial-key span { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); letter-spacing: .14em; }
.toast {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom));
    background: rgba(17,17,17,.92); color: #fff; padding: 12px 16px; border-radius: 999px; z-index: 80; font-size: 14px;
}
@media (min-width: 760px) {
    .phone-shell { padding: 18px; }
    .app-frame { min-height: calc(100vh - 36px); border-radius: 32px; overflow: hidden; }
    .bottom-nav { bottom: 18px; border-radius: 0 0 32px 32px; }
    .menu-panel { top: 136px; }
}
@media (max-width: 520px) {
    .compact-filters { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .app-header__top { min-height: 118px; }
    .app-header h1 { font-size: 34px; }
    .app-header p { font-size: 14px; }
}


/* v3 overrides */
.app-frame--contacts { padding-bottom: 0; }
.app-main--single { padding: 0 16px calc(28px + env(safe-area-inset-bottom)); }
.app-main--single .list-block { margin-bottom: 0; }
.toolbar-btn.hidden { display: none !important; }
.menu-panel { top: 110px; }
.toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (min-width: 760px) {
    .app-main--single { padding-bottom: 24px; }
    .toast { bottom: 32px; }
    .menu-panel { top: 128px; }
}
