:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
}

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

html, body, #app {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
    overflow-x: hidden;
}

button, input, select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.loading-spinner {
    font-size: 18px;
    color: var(--primary);
    font-weight: 600;
}

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-logo img {
    width: 38px;
    height: 38px;
    border-radius: 14px;
    object-fit: cover;
}

.topbar-label {
    display: grid;
    gap: 2px;
}

.topbar-title {
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
}

.topbar-subtitle {
    color: var(--muted);
    font-size: 12px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Main Layout */
.main-layout {
    display: flex;
    margin-top: 64px;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.sidebar-header {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

/* User Profile Card */
.user-profile-card {
    background: var(--surface);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    border: 1px solid var(--border);
}

.profile-banner {
    height: 80px;
    background-size: cover;
    background-position: center;
}

.profile-banner-color {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.profile-content {
    padding: 0 16px 16px 16px;
    position: relative;
}

.profile-avatar-container {
    margin-top: -36px;
    margin-bottom: 12px;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid var(--surface);
    object-fit: cover;
}

.profile-info {
    margin-bottom: 12px;
}

.profile-username {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.profile-userid {
    font-size: 12px;
    color: var(--muted);
}

.profile-roles {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.role-badge {
    display: inline-block;
    padding: 4px 10px;
    background: rgba(14, 165, 233, 0.15);
    color: #0369a1;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

/* Card Grid */
.card-grid {
    display: grid;
    gap: 10px;
}

.app-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.app-card:hover {
    transform: translateY(-2px);
    background: #f8fbff;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.app-card.active {
    background: rgba(14, 165, 233, 0.08);
    border-color: transparent;
    box-shadow: inset 4px 0 0 0 rgba(14, 165, 233, 0.65);
}

.app-card.app-card-success {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.35);
}

.app-card.app-card-success:hover {
    background: rgba(16, 185, 129, 0.12);
}

.app-card.app-card-success.active {
    background: rgba(16, 185, 129, 0.08);
    border-color: transparent;
    box-shadow: inset 4px 0 0 0 rgba(16, 185, 129, 0.65);
}

.app-card-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: transparent;
    color: var(--primary);
    font-size: 22px;
    flex-shrink: 0;
}

.app-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.app-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.app-card-desc {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.4;
}

/* Content Area */
.content-area {
    flex: 1;
    background: var(--bg);
    padding: 24px;
    overflow-y: auto;
}

/* Tab Navigation */
.tab-navigation {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    padding: 8px;
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.tab-button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-button:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.tab-button-active {
    background: var(--primary);
    color: white;
}

.tab-button-active:hover {
    background: var(--primary);
    color: white;
}

/* Admin Tabs */
.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.admin-tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: -2px;
}

.admin-tab:hover {
    color: var(--text);
    background: rgba(14, 165, 233, 0.05);
}

.admin-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(14, 165, 233, 0.08);
}

/* Panel */
.panel {
    background: var(--surface);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--border);
}

.panel-body {
    padding: 32px;
}

.panel-section {
    margin-bottom: 32px;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.panel-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
}

.panel-description {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 16px;
    line-height: 1.6;
}

/* Forms */
.form-inline {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.form-inline .field-input {
    flex: 1;
    min-width: 200px;
}

.field-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    background: var(--surface-muted);
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(88, 101, 242, 0.15);
    outline: none;
}

.field-input::placeholder {
    color: #94a3b8;
}

select.field-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Buttons */
.primary-button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 14px 18px;
    font-size: 14px;
    font-weight: 700;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 12px 32px rgba(14, 165, 233, 0.18);
}

.primary-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.primary-button:active {
    transform: translateY(0);
}

.secondary-button {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.secondary-button:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
}

.danger-button {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.2s ease, transform 0.2s ease;
}

.danger-button:hover {
    background: var(--danger-dark);
    transform: translateY(-1px);
}

.button-full {
    width: 100%;
    padding: 14px;
}

.discord-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

/* Messages */
.message-box {
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 13px;
    margin-bottom: 18px;
    line-height: 1.5;
}

.message-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.message-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* Alert */
.alert {
    border-radius: 14px;
    padding: 16px 18px;
    font-size: 14px;
    line-height: 1.6;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Hardware List */
.hardware-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hardware-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--surface-muted);
    border-radius: 16px;
    border: 1px solid var(--border);
    transition: box-shadow 0.2s ease;
}

.hardware-item:hover {
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.hardware-info {
    flex: 1;
}

.hardware-id {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.hardware-details {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.hardware-code {
    font-size: 13px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-button {
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.badge-button:hover {
    transform: translateY(-1px);
    opacity: 0.8;
}

.badge-info {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}

.badge-success {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}

/* Hardware Actions */
.hardware-actions {
    display: flex;
    gap: 8px;
}

.hardware-actions button {
    white-space: nowrap;
}

/* DNS Table */
.dns-table-container {
    overflow-x: auto;
    margin-top: 16px;
}

.dns-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
}

.dns-table thead {
    background: var(--surface-muted);
}

.dns-table th,
.dns-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.dns-table th {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dns-table td {
    font-size: 14px;
    color: var(--text);
}

.dns-table tbody tr:hover {
    background: var(--surface-muted);
}

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

.dns-table th:last-child,
.dns-table td:last-child {
    text-align: right;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-card {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.file-viewer-modal {
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.file-viewer-meta {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--surface-muted);
    border-radius: 8px;
    text-align: center;
}

.file-viewer-content {
    flex: 1;
    overflow: auto;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    max-height: 60vh;
}

.file-viewer-content pre {
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.modal-card-danger {
    border-color: rgba(239, 68, 68, 0.3);
}

.modal-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 20px;
}

.modal-message {
    margin-bottom: 24px;
}

.modal-message p {
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 16px;
}

.modal-message p:last-child {
    margin-bottom: 0;
}

.modal-hwid {
    padding: 16px;
    background: var(--surface-muted);
    border-radius: 12px;
    margin: 16px 0;
    text-align: center;
}

.modal-alias {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.modal-code {
    font-size: 14px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
}

.modal-warning {
    color: var(--danger) !important;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Text Utilities */
.text-muted {
    color: var(--muted);
    font-size: 14px;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    inset: 0;
    background: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10000;
}

.login-card {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border-radius: 24px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.login-logo {
    display: grid;
    place-items: center;
    margin-bottom: 24px;
}

.login-logo img {
    width: 30%;
    max-width: 120px;
    height: auto;
    border-radius: 20px;
    object-fit: contain;
}

.login-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    text-align: center;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    margin-bottom: 28px;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }
}

@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 18px 16px;
    }

    .content-area {
        padding: 18px;
    }

    .form-inline {
        flex-direction: column;
    }

    .form-inline .field-input {
        min-width: 100%;
    }

    .hardware-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .hardware-actions {
        width: 100%;
    }

    .hardware-actions button {
        flex: 1;
    }

    .danger-button {
        width: auto;
    }

    .modal-card {
        padding: 24px;
        max-width: 90%;
    }
}

@media (max-width: 640px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        height: auto;
        padding: 18px;
        gap: 12px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .panel-body {
        padding: 20px;
    }

    .login-card {
        padding: 28px 24px;
    }
}
