:root {
    --bg: #ffffff;
    --bg-elevated: #f7f8fa;
    --card-bg: #ffffff;
    --card-bg-hover: #f5f3f0;
    --text: #1a1d21;
    --muted: #6b7785;
    --border: #e5e8ec;

    --accent: #ff6600;
    --accent-bright: #ff8533;
    --accent-dark: #cc5200;
    --accent-soft: rgba(255, 102, 0, 0.08);
    --focus-ring: rgba(255, 102, 0, 0.35);

    --cyan: #00acc1;
    --cyan-soft: rgba(0, 172, 193, 0.10);

    --badge-completed-bg: rgba(0, 172, 193, 0.12);
    --badge-completed-fg: #00838f;
    --badge-failed-bg: rgba(217, 48, 37, 0.10);
    --badge-failed-fg: #d93025;
    --badge-pending-bg: rgba(245, 159, 0, 0.12);
    --badge-pending-fg: #b25900;
    --badge-platform-bg: rgba(63, 81, 181, 0.10);
    --badge-platform-fg: #3949ab;

    --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

h1, h2 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

.container.narrow {
    max-width: 400px;
}

h1 {
    font-size: 1.3rem;
    margin: 0;
}

h2 {
    font-size: 1.05rem;
    margin: 16px 0 8px;
}

/* Top bar / brand */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
}

.topbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
    width: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
    margin: 0;
}

.brand-name span {
    color: var(--accent);
}

.brand-hero {
    flex-direction: column;
    text-align: center;
    gap: 12px;
    margin: 8px 0 28px;
}

.brand-hero .brand-name {
    font-size: 1.9rem;
}

.brand-tagline {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Auth page */

body.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    background:
        radial-gradient(ellipse 520px 360px at 50% -10%, var(--accent-soft), transparent 70%),
        var(--bg);
}

body.login-body main {
    margin: auto;
    padding-top: 0;
    width: 100%;
}

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

.subtitle {
    width: 100%;
    color: var(--muted);
    margin: 4px 0 0;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.link {
    color: var(--accent-dark);
    text-decoration: none;
    font-weight: 500;
}

.link:hover {
    text-decoration: underline;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 24px 0;
}

.error {
    color: var(--badge-failed-fg);
    margin: 8px 0 0;
    font-size: 0.9rem;
}

/* Cards */

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

.card-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-link {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    text-decoration: none;
    color: var(--text);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.card-link:active,
.card-link:hover {
    background: var(--card-bg-hover);
    border-color: var(--accent-dark);
}

.card-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-meta {
    width: 100%;
    color: var(--muted);
    font-size: 0.82rem;
    font-family: var(--font-mono);
}

/* Badges */

.badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--border);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-completed {
    background: var(--badge-completed-bg);
    color: var(--badge-completed-fg);
}

.badge-failed {
    background: var(--badge-failed-bg);
    color: var(--badge-failed-fg);
}

.badge-collecting,
.badge-downloading,
.badge-merging,
.badge-qr_generated,
.badge-pending {
    background: var(--badge-pending-bg);
    color: var(--badge-pending-fg);
}

.badge-latest {
    background: var(--accent);
    color: #1a1a1a;
}

.badge-platform {
    background: var(--badge-platform-bg);
    color: var(--badge-platform-fg);
}

.badge-awaiting_code,
.badge-awaiting_password {
    background: var(--badge-pending-bg);
    color: var(--badge-pending-fg);
}

/* Chips (contacts) */

.chip-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 0.85rem;
    font-family: var(--font-mono);
}

/* Forms */

form.card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 0;
}

label {
    font-size: 0.85rem;
    color: var(--muted);
}

input[type="text"] {
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    font-family: var(--font-mono);
    background: var(--bg-elevated);
    color: var(--text);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

button {
    padding: 11px 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #1a1a1a;
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) {
    background: var(--accent-dark);
    color: #fff;
}

button:active:not(:disabled) {
    opacity: 0.85;
}

button:disabled {
    background: var(--border);
    color: var(--muted);
    cursor: not-allowed;
}

/* Chat view - bright, platform-styled thread (own scoped palette) */

/* WhatsApp (default) */
body.chat-body {
    --bg: #e5ddd5;
    --card-bg: #ffffff;
    --text: #1f2328;
    --muted: #667781;
    --border: #d9d4cb;
    --accent: #25d366;
    --accent-dark: #1f8a6e;
    --bubble-me: #d9fdd3;
    --bubble-them: #ffffff;
    font-family: var(--font-body);
}

/* Telegram */
body.chat-telegram {
    --bg: #dceefb;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --muted: #8b9aa6;
    --border: #d2e3f0;
    --accent: #2aabee;
    --accent-dark: #4ea4de;
    --bubble-me: #e1f4ff;
    --bubble-them: #ffffff;
}

.chat-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--accent-dark);
    color: #ffffff;
    position: sticky;
    top: 0;
    z-index: 1;
}

.chat-header h1 {
    flex: 1;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header .link {
    color: #ffffff;
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg);
}

.bubble-row {
    display: flex;
    width: 100%;
}

.bubble-row.me {
    justify-content: flex-end;
}

.bubble-row.them {
    justify-content: flex-start;
}

.bubble {
    max-width: 78%;
    padding: 6px 9px;
    border-radius: 8px;
    background: var(--bubble-them);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
    font-size: 0.95rem;
}

.bubble-row.me .bubble {
    background: var(--bubble-me);
}

.bubble-sender {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-dark);
    margin-bottom: 2px;
}

.bubble-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble-time {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--muted);
    text-align: right;
    margin-top: 2px;
}

.bubble-media {
    max-width: 100%;
    max-height: 280px;
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
}

.bubble-audio {
    display: block;
    margin-bottom: 4px;
    max-width: 100%;
}

.bubble-file {
    display: inline-block;
    margin-bottom: 4px;
    color: var(--accent-dark);
    text-decoration: none;
    font-weight: 600;
}

.bubble-file-missing {
    color: var(--muted);
    font-weight: 600;
}

.bubble-missing-note {
    font-weight: 400;
    font-style: italic;
}

/* Collapsible sections (e.g. contacts) */

.section-collapsible summary {
    cursor: pointer;
    list-style: none;
}

.section-collapsible summary::-webkit-details-marker {
    display: none;
}

.section-collapsible summary h2 {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.section-collapsible summary h2::before {
    content: '▶';
    font-size: 0.7em;
    color: var(--accent);
    transition: transform 0.15s ease;
}

.section-collapsible[open] summary h2::before {
    transform: rotate(90deg);
}

@media (min-width: 600px) {
    .container {
        padding: 32px;
    }

    .topbar .container {
        padding: 0 32px;
    }
}

@media (min-width: 700px) {
    .chat-body {
        max-width: 700px;
        margin: 0 auto;
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}
