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

:root {
    --primary: #4285F4;
    --primary-dark: #357ae8;
    --secondary: #34A853;
    --danger: #dc3545;
    --warning: #ffc107;
    --bg: #ffffff;
    --bg-alt: #f5f5f5;
    --text: #333333;
    --border: #ddd;
    --success: #28a745;
    --error: #dc3545;
    --info: #17a2b8;
}

body.dark,
body.dark-mode {
    --bg: #1e1e1e;
    --bg-alt: #2d2d2d;
    --text: #e0e0e0;
    --border: #444;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    min-height: 100vh;
    color: var(--text);
    transition: all 0.3s ease;
}

body.dark {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

/* ============================================================================
   LAYOUT & CONTAINERS
   ============================================================================ */

.container {
    max-width: 500px;
    margin: 40px auto;
    padding: 0 20px;
}

body.logged-in .container {
    max-width: 1000px;
}

.admin-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.card {
    background: var(--bg);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    color: var(--text);
}

.admin-card {
    background: var(--bg);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 10;
}

.logged-in .header {
    max-width: 100%;
}

body:not(.logged-in) .header {
    max-width: 500px;
    margin: 0 auto;
    border-radius: 0 0 12px 12px;
}

.header h1 {
    color: white !important;
    margin: 0;
    font-size: 1.8em;
}

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

.header h1 {
    font-size: 2em;
}

.admin-header h1 {
    font-size: 1.8em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
    color: white;
}

.dark-toggle {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2em;
    transition: background 0.3s;
    width: auto !important;
    min-width: 50px;
}

.dark-toggle:hover {
    background: rgba(255,255,255,0.3);
}

.logout-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.3s;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* ============================================================================
   TYPOGRAPHY
   ============================================================================ */

h1 {
    font-size: 2em;
    color: var(--primary);
}

.header h1 {
    color: white !important;
}

h2 {
    font-size: 1.3em;
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

h3 {
    font-size: 1.1em;
    color: var(--primary);
    margin-bottom: 10px;
}

h4 {
    color: var(--primary);
    margin-bottom: 10px;
}

small {
    display: block;
    margin-top: 5px;
    color: var(--text);
    opacity: 0.7;
}

hr {
    margin: 30px 0;
    border: none;
    border-top: 1px solid var(--border);
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text);
}

input[type="email"],
input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1em;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.3s, background 0.3s;
    font-family: inherit;
}

/* Dark mode input styling */
body.dark input[type="email"],
body.dark input[type="text"],
body.dark input[type="password"],
body.dark input[type="number"],
body.dark input[type="url"],
body.dark select,
body.dark textarea {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
}

body.dark-mode input[type="email"],
body.dark-mode input[type="text"],
body.dark-mode input[type="password"],
body.dark-mode input[type="number"],
body.dark-mode input[type="url"],
body.dark-mode select,
body.dark-mode textarea {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

button {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background 0.3s;
    width: 100%;
}

button:hover {
    background: var(--primary-dark);
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

button.secondary {
    background: #6c757d;
    color: white;
}

button.secondary:hover {
    background: #5a6268;
}

button.danger {
    background: var(--danger);
}

button.danger:hover {
    background: #c82333;
}

button.small {
    padding: 6px 12px;
    font-size: 0.9em;
    width: auto;
    margin: 0;
}

button.small-btn {
    padding: 6px 12px;
    font-size: 0.85em;
    margin: 0 5px;
    width: auto;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.button-group button {
    margin: 0;
}

/* ============================================================================
   ALERTS & MESSAGES
   ============================================================================ */

.alert {
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: none;
    border-left: 4px solid;
}

.alert.show {
    display: block;
}

.alert.error {
    background: #f8d7da;
    border-color: var(--danger);
    color: #721c24;
}

body.dark .alert.error,
body.dark-mode .alert.error {
    background: #3d2021;
    color: #f8d7da;
}

.alert.success {
    background: #d4edda;
    border-color: var(--success);
    color: #155724;
}

body.dark .alert.success,
body.dark-mode .alert.success {
    background: #1d3a1d;
    color: #d4edda;
}

.alert.info {
    background: #d1ecf1;
    border-color: var(--info);
    color: #0c5460;
}

body.dark .alert.info,
body.dark-mode .alert.info {
    background: #1d3a40;
    color: #d1ecf1;
}

.info-box {
    background: var(--bg);
    border-left: 4px solid var(--info);
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    color: var(--text);
}

/* ============================================================================
   BADGES
   ============================================================================ */

.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    background: #ffc107;
    color: black;
    margin-top: 10px;
}

.badge.success,
.badge-success {
    background: #d4edda;
    color: #155724;
}

body.dark .badge.success,
body.dark .badge-success,
body.dark-mode .badge.success,
body.dark-mode .badge-success {
    background: #1d3a1d;
    color: #d4edda;
}

.badge.danger,
.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

body.dark .badge.danger,
body.dark .badge-danger,
body.dark-mode .badge.danger,
body.dark-mode .badge-danger {
    background: #3d2021;
    color: #f8d7da;
}

.badge.info {
    background: #d1ecf1;
    color: #0c5460;
}

body.dark .badge.info,
body.dark-mode .badge.info {
    background: #1d3a40;
    color: #d1ecf1;
}

/* ============================================================================
   LISTS
   ============================================================================ */

.passkey-list {
    list-style: none;
    margin-bottom: 20px;
}

.passkey-item {
    background: var(--bg);
    padding: 15px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.passkey-item > div {
    flex: 1;
    min-width: 200px;
}

.passkey-item small {
    color: var(--text);
    opacity: 0.7;
}

.passkey-item .action-buttons {
    flex-shrink: 0;
}

.action-buttons {
    display: flex;
    gap: 5px;
}

/* ============================================================================
   DIVIDERS
   ============================================================================ */

.divider {
    text-align: center;
    margin: 20px 0;
    color: var(--text);
    opacity: 0.7;
}

.divider::before,
.divider::after {
    content: '';
    display: inline-block;
    width: 45%;
    height: 1px;
    background: var(--border);
    vertical-align: middle;
}

.divider::before {
    margin-right: 10px;
}

.divider::after {
    margin-left: 10px;
}

/* ============================================================================
   GRIDS
   ============================================================================ */

.script-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.script-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
    background: var(--bg);
}

.script-card h3 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1em;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.permission-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
    background: var(--bg);
}

.permission-card h4 {
    margin-bottom: 10px;
    color: var(--primary);
}

.permission-card button {
    width: 100%;
    margin-top: 10px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.stat-value {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--primary);
}

.stat-label {
    color: var(--text);
    opacity: 0.7;
    margin-top: 5px;
}

/* ============================================================================
   TABLES
   ============================================================================ */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

thead {
    background: var(--bg-alt);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
    color: var(--text);
}

tbody tr:hover {
    background: var(--bg-alt);
    color: var(--text);
    transition: background 0.2s ease;
}

/* ============================================================================
   TABS
   ============================================================================ */

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
}

.tab-button {
    padding: 12px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: var(--text);
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    width: auto;
}

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

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

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* ============================================================================
   LINKS
   ============================================================================ */

.admin-link {
    display: inline-block;
    margin-left: 10px;
    padding: 12px 24px;
    background: #ffc107;
    color: black;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    transition: background 0.3s;
}

.admin-link:hover {
    background: #ffb300;
}

a {
    color: var(--primary);
}

a:hover {
    text-decoration: underline;
}

/* ============================================================================
   SPINNERS & LOADING
   ============================================================================ */

.spinner {
    border: 3px solid rgba(66, 133, 244, 0.3);
    border-radius: 50%;
    border-top: 3px solid var(--primary);
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================================================
   MODALS (Edit Script, Batch, Timeout)
   ============================================================================ */

#editScriptModal,
#batchModal,
#timeoutModal {
    background: rgba(0, 0, 0, 0.5) !important;
}

#editScriptModal > div,
#batchModal > div,
#timeoutModal > div {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}

#editScriptModal input,
#editScriptModal textarea,
#editScriptModal select,
#batchModal input,
#batchModal textarea,
#batchModal select,
#timeoutModal input,
#timeoutModal textarea,
#timeoutModal select {
    background: var(--bg) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}

#editScriptModal input:focus,
#editScriptModal textarea:focus,
#editScriptModal select:focus,
#batchModal input:focus,
#batchModal textarea:focus,
#batchModal select:focus,
#timeoutModal input:focus,
#timeoutModal textarea:focus,
#timeoutModal select:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1) !important;
}

#editScriptModal h3,
#batchModal h3,
#timeoutModal h3,
#editScriptModal label,
#batchModal label,
#timeoutModal label {
    color: var(--text) !important;
}

#editScriptModal small,
#batchModal small,
#timeoutModal small {
    color: var(--text) !important;
    opacity: 0.7;
}

#batchModal small {
    color: var(--text) !important;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
    .container {
        margin: 20px auto;
        padding: 0 15px;
    }

    body.logged-in .container {
        max-width: 100%;
    }

    .admin-container {
        padding: 15px;
    }

    .card {
        padding: 25px;
    }

    .admin-card {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    h2 {
        font-size: 1.1em;
    }

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

    button {
        padding: 10px 16px;
        font-size: 0.95em;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    .script-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .permission-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .stats {
        grid-template-columns: 1fr;
    }

    table {
        font-size: 0.85em;
    }

    th, td {
        padding: 8px;
    }

    .passkey-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .passkey-item .action-buttons {
        width: 100%;
        justify-content: flex-start;
    }

    .passkey-item > div {
        width: 100%;
    }

    .user-info {
        flex-direction: column;
        gap: 10px;
        align-items: flex-end;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 10px;
    }

    .card {
        padding: 20px;
        border-radius: 8px;
    }

    h1 {
        font-size: 1.3em;
    }

    h2 {
        font-size: 1em;
    }

    button {
        padding: 10px 12px;
        font-size: 0.9em;
    }

    table {
        font-size: 0.75em;
    }

    th, td {
        padding: 6px;
    }

    .script-grid {
        grid-template-columns: 1fr;
    }

    .permission-grid {
        grid-template-columns: 1fr;
    }
}