:root {
    --bg: #0a0a0a;
    --bg-2: #141414;
    --bg-3: #1a1a1a;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --green: #009a32;
    --green-hover: #00b73c;
    --green-soft: rgba(0, 154, 50, 0.14);
    --text: #f5f5f5;
    --text-muted: #9ca3af;
    --text-faint: #6b7280;
    --radius: 10px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
}

button, input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

::placeholder {
    color: var(--text-faint);
}

.scrollbar::-webkit-scrollbar {
    width: 8px;
}
.scrollbar::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
}

/* Layout general */
.app-shell {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 268px;
    flex-shrink: 0;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    padding: 0 4px;
    text-decoration: none;
    color: inherit;
}

.brand img {
    height: 32px;
    width: auto;
}

.brand-text .brand-title {
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.04em;
}

.brand-text .brand-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.view-switch {
    display: flex;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 20px;
    gap: 2px;
}
.view-switch a {
    flex: 1;
    text-align: center;
    padding: 7px 8px;
    border-radius: 5px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
}
.view-switch a.active {
    background: var(--green);
    color: #05170a;
}
.view-switch a:not(.active):hover {
    color: var(--text);
}

.sidebar-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-faint);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin: 4px 4px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-list {
    list-style: none;
    margin: 0 0 20px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
}

.app-list-item:hover {
    background: var(--bg-3);
}

.app-list-item.active {
    background: var(--green-soft);
    border-color: rgba(0, 154, 50, 0.35);
}

.app-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.app-list-item .count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-faint);
}

.icon-btn {
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.icon-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.conversations-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
    border: 1px solid transparent;
}
.conversation-item:hover {
    background: var(--bg-3);
}
.conversation-item.active {
    background: var(--bg-3);
    border-color: var(--border-strong);
}

.conversation-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.conversation-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 11px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.conversation-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.btn-new {
    width: 100%;
    margin-top: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px dashed var(--border-strong);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
}
.btn-new:hover {
    color: var(--text);
    border-color: var(--green);
}

.user-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px 0;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    padding-top: 14px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--green-soft);
    color: var(--green);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
    position: relative;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    position: absolute;
    bottom: -1px;
    right: -1px;
    border: 2px solid var(--bg-2);
}

.user-footer .name {
    font-size: 13px;
    font-weight: 600;
}
.user-footer .role {
    font-size: 11px;
    color: var(--text-muted);
}

.user-footer form {
    margin-left: auto;
}
.user-footer button {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
}
.user-footer button:hover {
    color: var(--text);
}

/* Main column */
.main-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 60px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
}

.app-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}

.topbar-search {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    color: var(--text-muted);
    font-size: 13px;
    width: 260px;
}
.topbar-search input {
    background: none;
    border: none;
    outline: none;
    flex: 1;
    color: var(--text);
}
.kbd {
    font-size: 11px;
    color: var(--text-faint);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 1px 5px;
}

/* Chat */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 28px 0 12px;
}

.chat-inner {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.msg-row {
    display: flex;
    gap: 12px;
}

.msg-row.user {
    justify-content: flex-end;
}

.msg-bubble {
    background: #ececec;
    color: #111;
    padding: 10px 14px;
    border-radius: 14px 14px 2px 14px;
    max-width: 70%;
    font-size: 14px;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 4px;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
}

.ai-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 154, 50, 0.4);
    color: var(--green);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-content {
    max-width: 80%;
}

.ai-text {
    font-size: 14px;
    white-space: pre-wrap;
}

.ai-text a {
    color: var(--green);
    text-decoration: underline;
}
.ai-text code {
    background: var(--bg-3);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}
.ai-text strong {
    font-weight: 700;
}

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 10px;
    text-decoration: none;
    cursor: pointer;
}
.source-chip:hover {
    border-color: var(--border-strong);
    color: var(--text);
}
.source-chip .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.ai-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}
.ai-actions button {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 0;
}
.ai-actions button:hover {
    color: var(--text-muted);
    text-decoration: underline;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    max-width: 420px;
}
.chat-empty h2 {
    color: var(--text);
    font-size: 18px;
}

.chat-input-wrap {
    padding: 12px 24px 20px;
    flex-shrink: 0;
}

.chat-input-inner {
    max-width: 760px;
    margin: 0 auto;
}

.chat-input-box {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 10px 10px 14px;
}

.chat-input-box textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    max-height: 140px;
    line-height: 1.5;
    padding: 6px 0;
}

.attach-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: not-allowed;
    padding: 6px;
    flex-shrink: 0;
}

.send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--green);
    border: none;
    color: #05170a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.send-btn:hover {
    background: var(--green-hover);
}
.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-tip {
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
}

.mention-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 8px;
    background: var(--bg-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    width: 260px;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    z-index: 20;
}
.mention-menu.open {
    display: block;
}
.mention-item {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}
.mention-item:hover, .mention-item.sel {
    background: var(--bg-2);
}

/* Admin */
.admin-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px 40px;
    position: relative;
}

.admin-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.tab.active {
    color: var(--green);
    border-bottom-color: var(--green);
    font-weight: 600;
}

.entries-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
@media (max-width: 1100px) {
    .entries-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
    .entries-grid { grid-template-columns: 1fr; }
}

.entry-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.entry-card:hover {
    border-color: var(--border-strong);
}
.entry-card.pinned {
    border-color: rgba(0, 154, 50, 0.5);
}

.entry-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    color: var(--text-faint);
}

.entry-title {
    font-weight: 600;
    font-size: 14px;
}

.entry-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tag-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.tag-chip {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--green-soft);
    color: var(--green);
}
.tag-chip.gray {
    background: var(--bg-3);
    color: var(--text-muted);
}

.entry-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 8px;
}
.entry-footer .avatar {
    width: 22px;
    height: 22px;
    font-size: 10px;
}
.entry-footer .author {
    font-size: 12px;
    font-weight: 500;
}
.entry-footer .date {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-faint);
}

.fab {
    position: fixed;
    bottom: 30px;
    right: 36px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--green);
    color: #05170a;
    border: none;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 154, 50, 0.35);
}
.fab:hover {
    background: var(--green-hover);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    grid-column: 1 / -1;
}

/* Drawer */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 40;
}
.drawer-overlay.open {
    display: block;
}
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 480px;
    max-width: 92vw;
    background: var(--bg-2);
    border-left: 1px solid var(--border-strong);
    z-index: 41;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.2s ease;
}
.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.drawer-header h3 {
    margin: 0;
    font-size: 15px;
}
.drawer-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field select,
.field textarea {
    width: 100%;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    color: var(--text);
    outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--green);
}

.tags-input {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
}
.tags-input input {
    flex: 1;
    min-width: 80px;
    background: none;
    border: none;
    outline: none;
}
.tag-chip .rm {
    margin-left: 6px;
    cursor: pointer;
}

.md-toggle {
    display: flex;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.md-toggle button {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 6px 2px 10px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-size: 13px;
}
.md-toggle button.active {
    color: var(--text);
    border-bottom-color: var(--green);
}

.md-toolbar {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}
.md-toolbar button {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}
.md-toolbar button:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.md-editor {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    min-height: 260px;
    line-height: 1.6;
}

.md-preview {
    min-height: 260px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: none;
    font-size: 13.5px;
}
.md-preview.show {
    display: block;
}
.md-preview h1, .md-preview h2, .md-preview h3 {
    margin-top: 0;
}
.md-preview a { color: var(--green); }
.md-preview code {
    background: var(--bg-2);
    padding: 1px 5px;
    border-radius: 4px;
}
.md-preview blockquote {
    border-left: 3px solid var(--green);
    margin: 0;
    padding-left: 12px;
    color: var(--text-muted);
}

.drawer-footer {
    border-top: 1px solid var(--border);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.drawer-footer .meta {
    font-size: 11px;
    color: var(--text-faint);
    flex: 1;
}

.btn {
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
.btn:hover {
    border-color: var(--text-muted);
}
.btn-primary {
    background: var(--green);
    border-color: var(--green);
    color: #05170a;
    font-weight: 600;
}
.btn-primary:hover {
    background: var(--green-hover);
}
.btn-danger {
    color: #f87171;
}
.btn-danger:hover {
    border-color: #f87171;
}

/* Login */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    width: 360px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
}
.login-card img {
    height: 44px;
    margin-bottom: 20px;
}
.login-card h1 {
    font-size: 16px;
    margin: 0 0 4px;
}
.login-card p.sub {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0 0 22px;
}
.login-card .field {
    text-align: left;
    margin-bottom: 14px;
}
.login-error {
    background: rgba(248, 113, 113, 0.1);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 12.5px;
    margin-bottom: 16px;
}
.login-card button[type="submit"] {
    width: 100%;
    margin-top: 6px;
    padding: 10px;
}

/* Settings page */
.settings-form {
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.settings-group {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.settings-group h3 {
    margin: 0 0 14px;
    font-size: 14px;
}
.settings-group .field {
    margin-bottom: 12px;
}
.settings-group .field:last-child {
    margin-bottom: 0;
}
.radio-row {
    display: flex;
    gap: 16px;
}
.radio-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
}

.table-simple {
    width: 100%;
    border-collapse: collapse;
}
.table-simple th, .table-simple td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.table-simple th {
    color: var(--text-faint);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
}

.flash {
    background: var(--green-soft);
    color: var(--green);
    border: 1px solid rgba(0, 154, 50, 0.35);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* Hub de entrada (elegir Chat o Admin) */
.hub-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}
.hub-logo {
    height: 40px;
    margin-bottom: 28px;
}
.hub-title {
    font-size: 22px;
    margin: 0 0 6px;
}
.hub-sub {
    color: var(--text-muted);
    font-size: 13.5px;
    margin: 0 0 32px;
}
.hub-cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 720px;
}
.hub-card {
    width: 300px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px 22px;
    text-align: left;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s;
}
.hub-card:hover {
    border-color: var(--green);
}
.hub-card-icon {
    font-size: 26px;
    margin-bottom: 10px;
}
.hub-card-title {
    font-weight: 700;
    font-size: 16px;
}
.hub-card-sub {
    font-size: 12px;
    color: var(--green);
    margin: 2px 0 12px;
}
.hub-card p {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}
