:root {
    --rt-bottle-green: #0b4f3f;
    --rt-bottle-green-dark: #073a2e;
    --rt-bottle-green-light: #1a6e58;
    --rt-yellow: #ffe28a;
    --rt-yellow-soft: #fff6e0;
    --rt-orange: #f2994a;
    --rt-orange-dark: #d9782e;
    --rt-bg: #f4f1e8;
    --rt-bubble-out: #d8f2e6;
    --rt-bubble-in: #ffffff;
    --rt-text: #1f2a24;
    --rt-text-muted: #6b7770;
    --rt-danger: #d64545;
    --rt-radius: 14px;
    --rt-shadow: 0 2px 10px rgba(11,79,63,0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { overflow-x: hidden; width: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--rt-bg);
    color: var(--rt-text);
}
a { color: var(--rt-bottle-green); text-decoration: none; }

.rt-app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.rt-sidebar {
    width: 76px;
    background: var(--rt-bottle-green-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 8px;
}
.rt-sidebar .rt-logo { color: var(--rt-yellow); font-weight: 700; margin-bottom: 20px; font-size: 20px; }
.rt-nav-item {
    width: 52px; height: 52px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    color: #cfe8dd; position: relative; font-size: 22px;
}
.rt-nav-item.active { background: var(--rt-bottle-green-light); color: #fff; }
.rt-nav-item .badge {
    position: absolute; top: -2px; right: -2px;
    background: var(--rt-orange); color: #fff; font-size: 11px;
    border-radius: 10px; padding: 1px 6px; font-weight: 700;
}
.rt-nav-badge {
    position: absolute; top: 2px; right: 22%;
    background: var(--rt-orange); color: #fff; font-size: 10px;
    border-radius: 9px; padding: 0 5px; font-weight: 700; line-height: 15px; min-width: 15px; text-align: center;
}
.rt-sidebar-bottom { margin-top: auto; }

.rt-main { flex: 1; display: flex; overflow: hidden; min-height: 0; }

.rt-list-pane {
    width: 340px; border-right: 1px solid #e4ddc8; background: #fff;
    display: flex; flex-direction: column; min-height: 0;
}
.rt-list-pane-header {
    padding: 16px; border-bottom: 1px solid #eee2c4;
    background: var(--rt-yellow-soft);
}
.rt-list-pane-header h2 { margin: 0 0 8px; font-size: 18px; color: var(--rt-bottle-green-dark); }
.rt-search {
    width: 100%; padding: 9px 12px; border-radius: 20px; border: 1px solid #e3dcc2;
    background: #fff; font-size: 14px;
}
.rt-list { overflow-y: auto; flex: 1; min-height: 0; }
.rt-list-item {
    display: flex; gap: 10px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f4f0e2;
}
.rt-list-item:hover, .rt-list-item.active { background: #f6fbf8; }
.rt-avatar {
    width: 46px; height: 46px; border-radius: 50%; background: var(--rt-bottle-green);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; flex-shrink: 0; font-size: 16px;
}
.rt-list-item-title { font-weight: 600; font-size: 14.5px; }
.rt-list-item-sub { font-size: 13px; color: var(--rt-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.rt-list-item-meta { margin-left: auto; text-align: right; font-size: 11px; color: var(--rt-text-muted); }
.rt-unread-dot { background: var(--rt-orange); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700; }

.rt-content-pane { flex: 1; display: flex; flex-direction: column; background: #efe9d8; min-height: 0; min-width: 0; }

.rt-thread-header {
    padding: 12px 20px; background: var(--rt-bottle-green); color: #fff;
    display: flex; align-items: center; gap: 12px; box-shadow: var(--rt-shadow);
}
.rt-thread-header .rt-avatar { background: var(--rt-yellow); color: var(--rt-bottle-green-dark); }

.rt-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 6px; }
.rt-bubble-row { display: flex; }
.rt-bubble-row.out { justify-content: flex-end; }
.rt-bubble {
    max-width: 62%; padding: 8px 12px; border-radius: var(--rt-radius); font-size: 14.5px;
    box-shadow: var(--rt-shadow); line-height: 1.4;
}
.rt-bubble-row.out .rt-bubble { background: var(--rt-bubble-out); border-bottom-right-radius: 4px; }
.rt-bubble-row.in .rt-bubble { background: var(--rt-bubble-in); border-bottom-left-radius: 4px; }
.rt-bubble .sender { font-size: 12px; font-weight: 700; color: var(--rt-bottle-green); margin-bottom: 2px; }
.rt-bubble .meta { font-size: 10.5px; color: var(--rt-text-muted); margin-top: 3px; text-align: right; }
.rt-bubble .attachment { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.03); padding: 6px 10px; border-radius: 8px; margin-top: 4px; }
.rt-chat-img-wrap { display: block; margin-top: 4px; cursor: zoom-in; }
.rt-chat-img { max-width: 240px; max-height: 260px; width: 100%; border-radius: 12px; object-fit: cover; display: block; }
.rt-attach-preview { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--rt-yellow-soft); border-top: 1px solid #e4ddc8; }
.rt-attach-preview-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.rt-attach-preview-icon { font-size: 24px; flex-shrink: 0; }
.rt-attach-preview-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--rt-bottle-green-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-attach-preview-name small { font-weight: 400; color: var(--rt-text-muted); }
.rt-attach-preview-remove { border: none; background: rgba(0,0,0,0.08); border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: 13px; flex-shrink: 0; }
.mention { background: var(--rt-yellow-soft); color: var(--rt-orange-dark); font-weight: 700; padding: 0 3px; border-radius: 4px; }
.rt-system-msg { display: flex; justify-content: center; margin: 6px 0; }
.rt-system-msg span { background: rgba(11,79,63,0.08); color: var(--rt-text-muted); font-size: 12px; padding: 5px 14px; border-radius: 14px; text-align: center; max-width: 85%; }
.rt-kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.rt-kanban-tabs { display: none; }
.rt-status-pill { display: inline-block; background: var(--rt-yellow-soft); color: var(--rt-orange-dark); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 12px; }

.rt-list-tabs { display: flex; gap: 4px; padding: 0 12px 10px; }
.rt-list-tab { flex: 1; text-align: center; padding: 7px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--rt-bottle-green-dark); background: #fff; cursor: pointer; border: 1px solid #e3dcc2; }
.rt-list-tab.active { background: var(--rt-bottle-green); color: #fff; border-color: var(--rt-bottle-green); }
.rt-filter-row { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.rt-filter-chip { padding: 5px 12px; border-radius: 14px; font-size: 12px; font-weight: 600; background: #fff; border: 1px solid #e3dcc2; color: var(--rt-text-muted); cursor: pointer; }
.rt-filter-chip.active { background: var(--rt-orange); border-color: var(--rt-orange); color: #fff; }
.rt-mention-dropdown { position: absolute; bottom: 60px; left: 60px; right: 60px; background: #fff; border-radius: 10px; box-shadow: var(--rt-shadow); max-height: 180px; overflow-y: auto; display: none; z-index: 20; }
.rt-mention-item { padding: 8px 14px; cursor: pointer; font-size: 14px; }
.rt-mention-item:hover, .rt-mention-item.sel { background: var(--rt-yellow-soft); }

.rt-composer { display: flex; gap: 8px; padding: 12px 16px; background: #fff; border-top: 1px solid #e4ddc8; align-items: center; flex-shrink: 0; position: sticky; bottom: 0; z-index: 5; }
.rt-composer input[type=text] {
    flex: 1; padding: 11px 16px; border-radius: 22px; border: 1px solid #e3dcc2; font-size: 14.5px;
}
.rt-btn {
    background: var(--rt-bottle-green); color: #fff; border: none; border-radius: 22px;
    padding: 10px 18px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.rt-btn:hover { background: var(--rt-bottle-green-light); }
.rt-btn.orange { background: var(--rt-orange); }
.rt-btn.orange:hover { background: var(--rt-orange-dark); }
.rt-btn.ghost { background: transparent; color: var(--rt-bottle-green); border: 1px solid var(--rt-bottle-green); }
.rt-icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: #f1ede0; cursor: pointer; font-size: 18px; }

.rt-badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11.5px; font-weight: 700; }
.rt-badge.status-todo, .rt-badge.status-open { background: #fdecd8; color: var(--rt-orange-dark); }
.rt-badge.status-in_progress { background: #fff3b0; color: #8a6d00; }
.rt-badge.status-review { background: #e0e7ff; color: #3949ab; }
.rt-badge.status-done, .rt-badge.status-resolved, .rt-badge.status-closed { background: #d8f2e6; color: var(--rt-bottle-green-dark); }
.rt-badge.priority-urgent, .rt-badge.severity-critical { background: #ffe0e0; color: var(--rt-danger); }

.rt-card { background: #fff; border-radius: var(--rt-radius); box-shadow: var(--rt-shadow); padding: 16px; }
.rt-page { padding: 20px; overflow-y: auto; flex: 1; }
.rt-page h1 { color: var(--rt-bottle-green-dark); font-size: 22px; margin-top: 0; }

table.rt-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--rt-radius); overflow: hidden; }
table.rt-table th { background: var(--rt-yellow-soft); text-align: left; padding: 10px 12px; font-size: 13px; color: var(--rt-bottle-green-dark); }
table.rt-table td { padding: 10px 12px; border-top: 1px solid #f1ede0; font-size: 14px; }
table.rt-table tr:hover td { background: #fbfaf3; }

.rt-bottom-nav { display: none; }

@media (max-width: 860px) {
    .rt-sidebar { display: none; }
    .rt-list-pane { width: 100%; }
    .rt-list-pane.hide-on-mobile { display: none; }
    .rt-content-pane.hide-on-mobile { display: none; }
    .rt-content-pane.has-list-open { display: none; }
    .rt-app { flex-direction: column; }
    .rt-main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
    .mobile-back { display: inline-block !important; }
    .rt-bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
        background: var(--rt-bottle-green-dark); z-index: 50;
    }
    .rt-bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
        color: #cfe8dd; font-size: 11px; gap: 2px;
    }
    .rt-bottom-nav a.active { color: var(--rt-yellow); }

    /* Composer pinned to the bottom of the screen (above the bottom nav), fixed positioning —
       more reliable across phone browsers than relying purely on flex layout for this. */
    #typingIndicator, #inChatSearchResults { display: none !important; }
    .rt-composer {
        position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom));
        z-index: 45;
    }
    .rt-messages { padding-bottom: 76px; }
    .rt-attach-preview { position: fixed; left: 0; right: 0; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 44; }
}

.rt-login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--rt-bottle-green-dark), var(--rt-bottle-green)); }
.rt-login-card { background: #fff; padding: 36px; border-radius: 18px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.rt-login-card h1 { color: var(--rt-bottle-green-dark); font-size: 22px; margin-bottom: 4px; }
.rt-login-card p.sub { color: var(--rt-text-muted); margin-top: 0; font-size: 13px; }
.rt-login-card input { width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid #ddd; margin-bottom: 12px; font-size: 14px; }
.rt-login-card .rt-btn { width: 100%; padding: 12px; }
.rt-preview-modal { display:none; position:fixed; inset:0; background:rgba(7,58,46,0.92); z-index:200; align-items:center; justify-content:center; flex-direction:column; }
.rt-preview-modal.open { display:flex; }
.rt-preview-topbar { position:absolute; top:0; left:0; right:0; display:flex; align-items:center; justify-content:space-between; padding:14px 18px; color:#fff; }
.rt-preview-topbar .name { font-size:14px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:70vw; }
.rt-preview-topbar a, .rt-preview-topbar button { color:#fff; background:rgba(255,255,255,0.15); border:none; border-radius:8px; padding:8px 12px; font-size:14px; cursor:pointer; text-decoration:none; margin-left:8px; }
.rt-preview-body { max-width:92vw; max-height:88vh; display:flex; align-items:center; justify-content:center; }
.rt-error { background: #ffe0e0; color: var(--rt-danger); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ===== Mobile / responsiveness fixes ===== */

/* iOS Safari zooms the page on focusing any input under 16px — force 16px on every field */
input[type=text], input[type=password], input[type=email], input[type=date],
input[type=file], input[type=search], textarea, select {
    font-size: 16px;
}

/* Word-wrap long unbroken strings (URLs, filenames) instead of overflowing the bubble/card */
.rt-bubble, .rt-list-item-title, .rt-card, .rt-preview-topbar .name {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Bigger, easier-to-tap chips/tabs on touch screens */
.rt-list-tab { padding: 10px 7px; }
.rt-filter-chip { padding: 8px 14px; }
.rt-icon-btn { min-width: 40px; min-height: 40px; }

/* Respect iPhone home-indicator / notch safe areas */
.rt-bottom-nav { padding-bottom: env(safe-area-inset-bottom); height: calc(60px + env(safe-area-inset-bottom)); }
.rt-composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.rt-sidebar { padding-top: calc(16px + env(safe-area-inset-top)); }
.rt-preview-topbar { padding-top: calc(14px + env(safe-area-inset-top)); }

/* Tables scroll horizontally on narrow screens instead of squeezing/overflowing the page */
@media (max-width: 700px) {
    table.rt-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    /* Kanban board on phones: tab-select one status at a time (like the Chats/Team Members tabs), full-width cards — far more reliable than horizontal swipe-scroll across phone browsers */
    .rt-kanban-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
    .rt-kanban-tab {
        flex: 0 0 auto; padding: 8px 14px; border-radius: 14px; font-size: 12.5px; font-weight: 600;
        background: #fff; border: 1px solid #e3dcc2; color: var(--rt-text-muted); cursor: pointer; white-space: nowrap;
    }
    .rt-kanban-tab.active { background: var(--rt-bottle-green); border-color: var(--rt-bottle-green); color: #fff; }
    .rt-kanban { display: block; }
    .rt-kanban > div { display: none; }
    .rt-kanban > div.rt-col-active { display: block; }
}

/* Modals/cards that assumed desktop widths — cap to viewport on small phones */
#newConvModal .rt-card, #newTaskModal .rt-card, #newIssueModal .rt-card {
    width: min(380px, 92vw) !important;
    max-height: 88vh;
    overflow-y: auto;
}
.rt-login-card { width: min(340px, 92vw); }

@media (max-width: 480px) {
    .rt-page { padding: 14px; }
    .rt-page h1 { font-size: 19px; }
    .rt-card { padding: 12px; }
    .rt-thread-header { padding: 10px 12px; }
    .rt-messages { padding: 14px; }
    .rt-list-pane-header h2 { font-size: 16px; }
    .rt-preview-topbar .name { max-width: 50vw; font-size: 13px; }
    .rt-preview-topbar a, .rt-preview-topbar button { padding: 7px 9px; font-size: 13px; margin-left: 6px; }
    /* Grids (media gallery, admin cards) collapse to fewer columns instead of tiny squeezed tiles */
    div[style*="grid-template-columns:repeat(auto-fill,minmax(140px"] { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important; }
}

/* Landscape phones: shrink the fixed bottom nav a touch so it doesn't eat too much vertical space */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
    .rt-bottom-nav { height: calc(48px + env(safe-area-inset-bottom)); }
    .rt-bottom-nav a { font-size: 10px; }
}
