/* ============================================
   CRAXRAT Control Panel — Refined dark theme
   ============================================ */

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f26;
    --bg-tertiary: #252b33;
    --bg-card: #1e242b;
    --bg-elevated: #252b33;
    --border-color: #2d3540;
    --border-subtle: #252b33;

    --text-primary: #f0f2f5;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --accent: #0ea5e9;
    --accent-hover: #38bdf8;
    --accent-soft: rgba(14, 165, 233, 0.12);
    --accent-glow: rgba(14, 165, 233, 0.25);

    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);

    --sidebar-width: 240px;
    --header-height: 52px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
    --transition: 0.18s ease;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Subtle background gradient for depth */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse 120% 80% at 50% -20%, rgba(14, 165, 233, 0.06), transparent 50%),
                radial-gradient(ellipse 80% 50% at 100% 50%, rgba(30, 58, 138, 0.04), transparent 45%);
    pointer-events: none;
    z-index: 0;
}

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

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* ---------- Login page ---------- */
body.login-page .container {
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
}

body.login-page .footer {
    margin-top: auto;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.login-container::before {
    content: '';
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #06b6d4);
}

.login-container .inner {
    padding: 36px 32px 32px;
}

.login-container h1 {
    font-size: 1.625rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.login-container .subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 28px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-form input {
    width: 100%;
    padding: 13px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.login-form input::placeholder {
    color: var(--text-muted);
}
.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-form button {
    padding: 13px 20px;
    background: linear-gradient(180deg, var(--accent) 0%, #0284c7 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter var(--transition), transform 0.1s ease;
    margin-top: 4px;
}
.login-form button:hover {
    filter: brightness(1.08);
}
.login-form button:active {
    transform: scale(0.99);
}

.error {
    padding: 12px 16px;
    background: var(--error-bg);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius);
    color: #fca5a5;
    font-size: 0.875rem;
    margin-bottom: 20px;
}

/* ---------- App layout ---------- */
.app-wrapper {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
}

.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 0 24px;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-brand .logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(145deg, var(--accent), #06b6d4);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.05em;
}
.header-brand .logo-text {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 16px 0;
    flex-shrink: 0;
}

.sidebar h2 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0 16px 10px;
    margin-bottom: 4px;
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu li {
    margin: 0;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin: 0 10px;
    transition: color var(--transition), background var(--transition);
}
.sidebar-menu a:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}
.sidebar-menu a.active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 500;
}

.sidebar-menu .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.85;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-menu .icon svg {
    width: 18px;
    height: 18px;
}
.sidebar-menu a.active .icon {
    opacity: 1;
}

/* ---------- Main content ---------- */
.main-content {
    flex: 1;
    padding: 28px 32px 40px;
    overflow-x: auto;
    background: transparent;
}

.main-content h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 28px;
    max-width: 520px;
    line-height: 1.6;
}

/* ---------- Forms ---------- */
.device-form {
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.device-form select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color var(--transition);
}
.device-form select:focus {
    outline: none;
    border-color: var(--accent);
}

.device-form button[type="button"],
.device-form button[type="submit"] {
    padding: 12px 22px;
    background: linear-gradient(180deg, var(--accent) 0%, #0284c7 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter var(--transition), transform 0.1s;
    align-self: flex-start;
}
.device-form button:hover {
    filter: brightness(1.08);
}
.device-form button:active {
    transform: scale(0.98);
}

/* ---------- Tables ---------- */
.device-list {
    margin-top: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.device-list th,
.device-list td {
    padding: 14px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.device-list th {
    background: var(--bg-elevated);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.device-list tr:last-child td {
    border-bottom: none;
}

.device-list tbody tr {
    transition: background var(--transition);
}
.device-list tbody tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.no-devices {
    text-align: center;
    padding: 56px 28px;
    background: var(--bg-card);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
}

.no-devices p {
    font-size: 0.9rem;
    color: var(--text-muted);
    max-width: 360px;
    margin: 0 auto;
    line-height: 1.6;
}
.no-devices a {
    font-weight: 500;
}

/* ---------- Modal ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px 30px;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.modal-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
    line-height: 1.6;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.tg-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
    color: #fff !important;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9rem;
    transition: filter var(--transition);
}
.tg-button:hover {
    filter: brightness(1.1);
    color: #fff !important;
}

.cancel-button {
    padding: 12px 20px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.cancel-button:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* ---------- Footer ---------- */
.footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.footer a {
    color: var(--text-muted);
}
.footer a:hover {
    color: var(--text-secondary);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .app-wrapper {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 12px 0;
    }
    .sidebar h2 {
        display: none;
    }
    .sidebar-menu {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
        padding: 0 12px;
    }
    .sidebar-menu li {
        flex: 1;
        min-width: 120px;
    }
    .main-content {
        padding: 20px 16px 32px;
    }
    .device-list th,
    .device-list td {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
}
