/* ============================================================
   UNIMATE V3 — FRONT
   Tema terminal (portado de V2/CREWS/front src/assets/main.css)
   ============================================================ */

:root {
    --bg-color: #0a0a0a;
    --panel-bg: #111111;
    --accent-color: #00ff41;
    --accent-hover: #00e63a;
    --text-color: #00ff41;
    --secondary-text: #666666;
    --border-color: #222222;
    --input-bg: #000000;
    --danger-color: #ff4444;
    --info-color: #4fc1ff;
    --warn-color: #ffb627;
    --font-family: 'Fira Code', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 14px;
    color-scheme: dark;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- scrollbars ---------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #444;
}
* {
    scrollbar-width: thin;
    scrollbar-color: #333 var(--bg-color);
}

button {
    font-family: inherit;
    cursor: pointer;
    transition: all .2s ease;
}

.hidden {
    display: none !important;
}

/* ---------- animaciones ---------- */
@keyframes blink {
    50% { opacity: 0; }
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 5px rgba(0, 255, 65, 0.4); }
    50%      { box-shadow: 0 0 15px rgba(0, 255, 65, 0.8); }
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #0d150d 0%, var(--bg-color) 70%);
    padding: 20px;
}

.login-card {
    width: 400px;
    max-width: 100%;
    background: var(--panel-bg);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
    padding: 30px;
    animation: fadeIn .3s ease;
}

.login-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 25px;
}

.login-header h1 {
    font-size: 14px;
    color: var(--secondary-text);
    font-weight: 500;
    letter-spacing: 1px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-color);
    animation: blink 1s infinite;
    flex-shrink: 0;
}

.field-label {
    display: block;
    font-size: 10px;
    color: var(--secondary-text);
    margin: 14px 0 4px;
    letter-spacing: 2px;
}

.login-card input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 13px;
    padding: 9px 10px;
}

.login-card input::placeholder {
    color: #444;
}

.login-card input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 5px rgba(0, 255, 65, 0.3);
}

.login-error {
    display: none;
    color: var(--danger-color);
    font-size: 11px;
    margin-top: 12px;
}

.login-error.visible {
    display: block;
    animation: fadeIn .2s ease;
}

.login-btn {
    width: 100%;
    margin-top: 22px;
    padding: 10px;
    background: var(--accent-color);
    color: #000;
    border: none;
    font-weight: bold;
    font-size: 12px;
    letter-spacing: 2px;
}

.login-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.4);
}

.login-footer {
    margin-top: 22px;
    font-size: 10px;
    color: #444;
    text-align: center;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- navbar ---------- */
.navbar {
    background: #000;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 54px;
    flex-shrink: 0;
}

.nav-logo {
    max-width: 129px;
    display: block;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.nav-btn .mdi {
    font-size: 16px;
}

.nav-btn:hover {
    color: var(--accent-color);
}

.nav-btn.active {
    color: var(--accent-color);
    text-shadow: 0 0 8px rgba(0, 255, 65, 0.5);
}

.nav-divider {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 8px;
}

.nav-user {
    font-size: 11px;
    color: #888;
    letter-spacing: 1px;
}

.nav-user b {
    color: var(--accent-color);
    font-weight: 600;
}

.logout-btn {
    background: transparent;
    border: none;
    color: #69f0ae;
    padding: 4px;
    display: flex;
    align-items: center;
}

.logout-btn .mdi {
    font-size: 18px;
}

.logout-btn:hover {
    color: var(--accent-color);
    text-shadow: 0 0 8px rgba(0, 255, 65, 0.5);
}

/* ---------- vistas ---------- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.view {
    flex: 1;
    display: none;
    flex-direction: column;
    min-height: 0;
}

.view.active {
    display: flex;
}

/* ============================================================
   CHAT
   ============================================================ */
.chatbot-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-color);
}

/* ---------- header ---------- */
.chat-header {
    padding: 10px 20px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 14px;
    color: var(--secondary-text);
    font-weight: 500;
}

.chat-header .path {
    color: #888;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #333;
    flex-shrink: 0;
}

.status-indicator.is-loading {
    background: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-color);
    animation: blink 1s infinite;
}

/* ---------- mensajes ---------- */
.chat-display {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message-wrapper {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    animation: fadeIn .15s ease;
}

.message-wrapper.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-meta {
    font-size: 10px;
    color: #444;
    margin-bottom: 4px;
    display: flex;
    gap: 10px;
    letter-spacing: 1px;
}

.role-tag {
    color: var(--accent-color);
    font-weight: bold;
}

.message-content {
    padding: 10px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 13px;
    line-height: 1.5;
}

.message-wrapper.user .message-content {
    background: #001a00;
    border-color: #00ff4133;
}

.message-wrapper.message-error .message-content {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.message-wrapper.message-warn .message-content {
    border-color: var(--warn-color);
    color: var(--warn-color);
}

.tool-call {
    color: var(--info-color);
    font-size: 11px;
    margin: 0;
    white-space: pre-wrap;
    font-family: inherit;
    line-height: 1.5;
}

.cursor {
    animation: blink 1s infinite;
}

/* ---------- tabla BOM ---------- */
.terminal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.terminal-table th {
    background: #181818;
    color: var(--secondary-text);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
}

.terminal-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

.terminal-table tr:last-child td {
    border-bottom: none;
}

/* ---------- input ---------- */
.chat-input-area {
    padding: 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--accent-color);
    padding: 8px;
    gap: 10px;
}

.input-wrapper.input-locked {
    border-color: #333;
    background: #050505;
    cursor: wait;
}

.input-wrapper .prefix {
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    padding: 5px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    max-height: 120px;
}

.input-wrapper textarea:focus {
    outline: none;
}

.input-wrapper textarea::placeholder {
    color: #444;
}

.send-btn {
    min-width: 60px;
    background: var(--accent-color);
    color: #000;
    border: none;
    font-weight: bold;
    font-size: 12px;
    letter-spacing: 1px;
    padding: 7px 14px;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.4);
}

.send-btn:disabled {
    background: #333;
    color: #666;
    cursor: wait;
}

.system-status {
    font-size: 10px;
    color: #444;
    margin-top: 10px;
    letter-spacing: 1px;
}

.system-status .ok {
    color: var(--accent-color);
}

.system-status .warn {
    color: var(--warn-color);
}

.system-status .dim {
    color: #666;
}

/* ============================================================
   PLACEHOLDERS (módulos futuros)
   ============================================================ */
.placeholder-view {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-card {
    background: var(--panel-bg);
    border: 1px dashed var(--border-color);
    padding: 40px 70px;
    text-align: center;
    animation: fadeIn .2s ease;
}

.placeholder-card .mdi {
    font-size: 44px;
    color: #333;
}

.placeholder-card h2 {
    font-size: 14px;
    color: var(--secondary-text);
    margin: 18px 0 8px;
    letter-spacing: 3px;
    font-weight: 500;
}

.placeholder-card p {
    font-size: 11px;
    color: #444;
    letter-spacing: 1px;
}

/* ============================================================
    MATERIAL (catálogo CRUD + búsqueda)
    ============================================================ */
.material-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.material-header {
    padding: 10px 20px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.material-header h1 {
    font-size: 14px;
    color: var(--secondary-text);
    font-weight: 500;
}

.material-header .path {
    color: #888;
}

.material-actions {
    display: flex;
    gap: 8px;
}

.btn-tool {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--secondary-text);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 7px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-tool .mdi {
    font-size: 14px;
}

.btn-tool:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(0, 255, 65, 0.25);
}

/* ---------- búsqueda ---------- */
.material-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 20px 0;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    flex-shrink: 0;
}

.material-search:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 5px rgba(0, 255, 65, 0.3);
}

.material-search .prefix {
    font-weight: bold;
    font-size: 14px;
}

.material-search input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: inherit;
    font-size: 13px;
}

.material-search input:focus {
    outline: none;
}

.material-search input::placeholder {
    color: #444;
}

.material-search .send-btn {
    min-width: 56px;
}

#mat-status {
    margin: 10px 20px 0;
}

/* ---------- tabla ---------- */
.material-table-wrap {
    flex: 1;
    overflow: auto;
    margin: 14px 20px 20px;
    border: 1px solid var(--border-color);
    min-height: 0;
}

.material-table {
    width: 100%;
    min-width: 560px;
}

.material-table th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.material-table td {
    font-size: 12px;
}

.material-table .td-ref {
    font-weight: 600;
}

.material-table .td-dim {
    color: var(--secondary-text);
}

.material-table tbody tr {
    cursor: pointer;
}

.material-table tbody tr:hover td {
    background: #001a00;
}

.ob-yes {
    color: var(--warn-color);
}

.ob-no {
    color: #555;
}

.col-actions {
    width: 90px;
    text-align: right;
}

.row-btn {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    padding: 2px 4px;
}

.row-btn .mdi {
    font-size: 16px;
}

.row-btn.edit:hover {
    color: var(--accent-color);
}

.row-btn.del:hover {
    color: var(--danger-color);
}

.material-empty {
    text-align: center;
    padding: 40px;
    color: #444;
    font-size: 12px;
    letter-spacing: 2px;
}

/* ---------- modal CRUD ---------- */
.mat-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}

.mat-modal-card {
    width: 720px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--panel-bg);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
    animation: fadeIn .2s ease;
}

.mat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    z-index: 1;
}

.mat-modal-header h2 {
    font-size: 13px;
    letter-spacing: 2px;
    color: var(--accent-color);
    font-weight: 600;
}

.mat-modal-x {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    font-size: 20px;
    padding: 0 4px;
}

.mat-modal-x:hover {
    color: var(--danger-color);
}

#mat-form {
    padding: 18px;
}

.mat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
}

.mat-field {
    display: flex;
    flex-direction: column;
}

.mat-field .field-label,
.mat-full .field-label {
    margin-top: 0;
}

.mat-input {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 12px;
    padding: 8px 10px;
    width: 100%;
}

.mat-input::placeholder {
    color: #444;
}

.mat-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 5px rgba(0, 255, 65, 0.3);
}

textarea.mat-input {
    resize: vertical;
    line-height: 1.5;
}

.mat-full {
    margin-top: 14px;
}

.mat-modal .req {
    color: var(--danger-color);
}

.mat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.save-btn {
    background: var(--accent-color);
    color: #000;
    border: none;
    font-weight: bold;
    font-size: 12px;
    letter-spacing: 2px;
    padding: 9px 24px;
}

.save-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.4);
}

.save-btn:disabled {
    background: #333;
    color: #666;
    cursor: wait;
}

/* ============================================================
    RULES (editor de prompt manual)
    ============================================================ */
.rules-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#rl-status {
    margin: 10px 20px 0;
}

.rules-editor-wrap {
    flex: 1;
    overflow: hidden;
    margin: 14px 20px 0;
    border: 1px solid var(--border-color);
    min-height: 0;
}

#rl-editor {
    width: 100%;
    height: 100%;
    background: var(--input-bg);
    border: none;
    color: var(--text-color);
    font-family: inherit;
    font-size: 12px;
    line-height: 1.6;
    padding: 12px 14px;
    resize: none;
    white-space: pre;
}

#rl-editor:focus {
    outline: none;
    box-shadow: inset 0 0 8px rgba(0, 255, 65, 0.15);
}

#rl-editor::placeholder {
    color: #444;
    line-height: 1.6;
}

#rl-editor::selection {
    background: rgba(0, 255, 65, 0.25);
}

.rules-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 10px;
    font-size: 10px;
    letter-spacing: 1px;
    color: #444;
    flex-shrink: 0;
}

#rl-dirty {
    color: var(--warn-color);
}

/* ============================================================
    RESPONSIVE
    ============================================================ */
@media (max-width: 768px) {
    .nav-logo {
        max-width: 90px;
    }
    .nav-btn span,
    .nav-user {
        display: none;
    }
    .nav-btn {
        padding: 8px;
    }
    .message-wrapper {
        max-width: 95%;
    }
}
