/* ==========================================================================
   Gamaedor Client Portal — App Styles
   ========================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

/* --- Navigation --- */
.app-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.5rem;
    height: 56px;
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-logo {
    width: 28px;
    height: 28px;
    background: var(--color-accent);
    color: #fff;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.brand-client {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--color-text);
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--color-text-dark);
    font-size: 0.9rem;
    transition: background 0.15s;
}

.nav-link:hover { background: var(--color-bg-dark); color: var(--color-text); }
.nav-link.active { background: var(--color-accent-light); color: var(--color-accent); font-weight: 600; }

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-username {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.nav-logout { color: var(--color-text-muted); font-size: 0.85rem; }
.nav-logout:hover { color: var(--color-error); }

/* --- App Content --- */
.app-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.app-content.login-page {
    max-width: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
}

.app-content.chat-page {
    max-width: none;
    padding: 0;
    height: calc(100vh - 56px);
}

/* --- Login --- */
.login-wrap {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: var(--color-bg-card);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 0.25rem;
}

.login-title {
    text-align: center;
    font-size: 1rem;
    color: var(--color-text-muted);
    font-weight: 400;
    margin-bottom: 1.5rem;
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-error);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-dark);
    margin-bottom: 0.35rem;
}

.login-form input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}

.login-form input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.btn-login {
    width: 100%;
    padding: 0.7rem;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 0.5rem;
}

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

/* --- Portal / Dashboard --- */
.portal-wrap { }

.portal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.portal-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.period-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--color-bg-card);
    cursor: pointer;
    outline: none;
}

.period-select:focus {
    border-color: var(--color-accent);
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1.25rem;
}

.card-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.35rem;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

/* Limit Bar */
.limit-bar {
    height: 6px;
    background: var(--color-bg-dark);
    border-radius: 3px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.limit-bar-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}

.limit-bar-fill.warning { background: var(--color-warning); }
.limit-bar-fill.danger { background: var(--color-error); }

/* Tabs */
.portal-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0;
}

.tab-btn {
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { color: var(--color-accent); border-bottom-color: var(--color-accent); font-weight: 600; }

.tab-content { display: block; }
.tab-content.hidden { display: none; }

/* Usage Chart */
.usage-chart {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1.5rem;
    min-height: 200px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 180px;
}

.chart-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 24px;
    background: var(--color-accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}

.chart-bar-label {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    margin-top: 4px;
    transform: rotate(-45deg);
    white-space: nowrap;
}

/* Agent Breakdown */
.agent-breakdown {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: start;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-dark);
}

.data-table td {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--color-border);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-bg); }

/* Sessions Table */
.sessions-table {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
}

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.active { background: rgba(34,197,94,0.1); color: var(--color-success); }
.status-badge.ended { background: var(--color-bg-dark); color: var(--color-text-muted); }

/* Loading State */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-muted);
}

.no-data {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* --- Chat --- */
.chat-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
    background: var(--color-bg-card);
    border-inline-start: 1px solid var(--color-border);
    border-inline-end: 1px solid var(--color-border);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-card);
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
    transition: background 0.3s;
}

.chat-status.connected .status-dot { background: var(--color-success); }
.chat-status.reconnecting .status-dot { background: var(--color-warning); animation: pulse 1.5s infinite; }
.chat-status.error .status-dot { background: var(--color-error); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.status-text {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.chat-title {
    font-weight: 600;
    font-size: 1rem;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-loading {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-muted);
}

.chat-msg {
    max-width: 75%;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
}

.chat-msg.own {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .chat-msg.own {
    border-bottom-right-radius: 12px;
    border-bottom-left-radius: 4px;
}

.chat-msg.other {
    align-self: flex-start;
    background: var(--color-bg-dark);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .chat-msg.other {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 4px;
}

.msg-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-accent);
    margin-bottom: 0.2rem;
}

.msg-time {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 0.2rem;
    text-align: end;
}

/* Chat Input */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-card);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
}

.chat-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.chat-send-btn {
    padding: 0.6rem 1.25rem;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.chat-send-btn:hover { background: var(--color-accent-hover); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Billing --- */
.billing-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 2rem;
}

.billing-card h2 {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
}

.billing-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.billing-stat {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.billing-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.billing-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.billing-subtitle {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

.billing-plan-info {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.plan-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.plan-label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.plan-value {
    font-size: 0.9rem;
    font-weight: 600;
}

.billing-note {
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.billing-note a { color: var(--color-accent); }

/* --- Users / Data Table --- */
.users-table-wrap {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th {
    text-align: start;
    padding: 0.75rem 1rem;
    background: var(--color-bg-dark);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-dark);
    border-bottom: 1px solid var(--color-border);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

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

.data-table tbody tr:hover { background: var(--color-accent-light); }

.row-inactive { opacity: 0.5; }

.user-name { font-weight: 600; }

.client-badge {
    background: var(--color-bg-dark);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.role-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.role-admin { background: rgba(var(--color-accent-rgb), 0.15); color: var(--color-accent); }
.role-member { background: rgba(59, 130, 246, 0.1); color: var(--color-info); }
.role-viewer { background: rgba(148, 163, 184, 0.15); color: var(--color-text-muted); }

.status-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-active { background: rgba(34, 197, 94, 0.1); color: var(--color-success); }
.status-inactive { background: rgba(239, 68, 68, 0.1); color: var(--color-error); }

.actions-cell {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.inline-form { display: inline; }

.btn-small {
    padding: 0.3rem 0.6rem;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: opacity 0.15s;
}

.btn-small:hover { opacity: 0.8; }

.btn-edit { background: var(--color-accent-light); color: var(--color-accent); }
.btn-delete { background: rgba(239, 68, 68, 0.1); color: var(--color-error); }

.btn-primary {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

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

.btn-secondary {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    background: var(--color-bg-dark);
    color: var(--color-text-dark);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-secondary:hover { background: var(--color-border); }

/* --- User Form --- */
.form-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 2rem;
    max-width: 600px;
}

.user-form { display: flex; flex-direction: column; gap: 1.25rem; }

.user-form .form-group { display: flex; flex-direction: column; gap: 0.35rem; }

.user-form label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-dark);
}

.user-form input[type="text"],
.user-form input[type="email"],
.user-form input[type="password"],
.user-form select {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    outline: none;
    background: var(--color-bg);
}

.user-form input:focus,
.user-form select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding-top: 0.5rem;
}

/* --- Terminal --- */
.terminal-page { padding: 0 !important; }

.terminal-wrap {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
}

.terminal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
    gap: 1rem;
    flex-shrink: 0;
}

.terminal-toolbar-left,
.terminal-toolbar-center,
.terminal-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.terminal-toolbar-center { flex: 1; justify-content: center; }

.btn-terminal {
    padding: 0.35rem 0.9rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.btn-connect {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.btn-connect:hover:not(:disabled) { background: var(--color-accent-hover); }
.btn-connect:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-disconnect {
    background: transparent;
    color: #ccc;
    border-color: #555;
}

.btn-disconnect:hover:not(:disabled) { background: rgba(255,255,255,0.05); color: #fff; }
.btn-disconnect:disabled { opacity: 0.3; cursor: not-allowed; }

.terminal-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
}

.terminal-status-indicator.connected { background: var(--color-success); }
.terminal-status-indicator.connecting { background: var(--color-warning); animation: pulse 1.5s infinite; }
.terminal-status-indicator.disconnected { background: #555; }
.terminal-status-indicator.error { background: var(--color-error); }

.terminal-status-text {
    font-size: 0.8rem;
    color: #999;
}

.terminal-session-id {
    font-size: 0.7rem;
    color: #666;
    font-family: monospace;
}

.terminal-viewport {
    flex: 1;
    background: #1e1e1e;
    position: relative;
    overflow: hidden;
}

.terminal-viewport .xterm {
    height: 100%;
    padding: 4px;
}

.terminal-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666;
}

.terminal-placeholder-icon {
    font-size: 3rem;
    font-family: monospace;
    color: var(--color-accent);
    opacity: 0.5;
    margin-bottom: 0.5rem;
}

.terminal-placeholder p {
    font-size: 0.9rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-nav { padding: 0 0.75rem; gap: 0.75rem; }
    .nav-links { gap: 0; }
    .nav-link { padding: 0.5rem; font-size: 0.8rem; }
    .nav-username { display: none; }
    .app-content { padding: 1rem; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .chat-msg { max-width: 85%; }
}

@media (max-width: 480px) {
    .summary-cards { grid-template-columns: 1fr; }
    .portal-header { flex-direction: column; align-items: stretch; gap: 0.75rem; }
    .billing-stats { grid-template-columns: 1fr; }
}
