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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #f0f2f5;
    color: #1a1a2e;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

a {
    color: #4f46e5;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ============================================================
   Layout
   ============================================================ */
.wrapper {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

main {
    flex: 1;
    padding: 2.5rem 0;
}

/* ============================================================
   Header & Navigation
   ============================================================ */
header {
    background-color: #1a1a2e;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.nav-brand {
    font-size: 1.35rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.5px;
    text-decoration: none;
}

.nav-brand:hover {
    text-decoration: none;
    color: #a5b4fc;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
}

.nav-links a {
    color: #c7d2fe;
    text-decoration: none;
    font-size: 0.925rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    transition: background-color 0.15s, color 0.15s;
}

.nav-links a:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    text-decoration: none;
}

.nav-link-logout {
    color: #fca5a5 !important;
}

.nav-link-logout:hover {
    background-color: rgba(239, 68, 68, 0.15) !important;
    color: #fca5a5 !important;
}

/* ============================================================
   Footer
   ============================================================ */
footer {
    background-color: #1a1a2e;
    color: #6b7280;
    text-align: center;
    padding: 1.25rem 0;
    font-size: 0.85rem;
    margin-top: auto;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    padding: 2.25rem 2rem;
    max-width: 480px;
    margin: 0 auto;
}

.card h2 {
    font-size: 1.5rem;
    color: #1a1a2e;
    margin-bottom: 1.5rem;
    font-weight: 700;
}

/* ============================================================
   Forms
   ============================================================ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.4rem;
}

.form-group input {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid #d1d5db;
    border-radius: 7px;
    font-size: 1rem;
    color: #1a1a2e;
    background-color: #fafafa;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    outline: none;
}

.form-group input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
    background-color: #ffffff;
}

.form-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9rem;
    color: #6b7280;
}

.form-footer a {
    color: #4f46e5;
    font-weight: 500;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-block;
    padding: 0.7rem 1.75rem;
    border-radius: 7px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
    text-align: center;
    line-height: 1.4;
}

.btn:hover {
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-full {
    width: 100%;
    display: block;
}

.btn-primary {
    background-color: #4f46e5;
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #4338ca;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background-color: #6b7280;
    color: #ffffff;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

.btn-danger {
    background-color: #ef4444;
    color: #ffffff;
}

.btn-danger:hover {
    background-color: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ============================================================
   Alert Messages
   ============================================================ */
.alert {
    padding: 0.85rem 1rem;
    border-radius: 7px;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.alert p + p {
    margin-top: 0.25rem;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* ============================================================
   Hero — Homepage
   ============================================================ */
.hero {
    text-align: center;
    padding: 4rem 1rem 3rem;
}

.hero h1 {
    font-size: 2.75rem;
    font-weight: 800;
    color: #1a1a2e;
    margin-bottom: 1rem;
    line-height: 1.15;
}

.hero p {
    font-size: 1.125rem;
    color: #6b7280;
    max-width: 520px;
    margin: 0 auto 2.25rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================================
   Dashboard
   ============================================================ */
.dashboard-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    padding: 2.25rem 2rem;
    max-width: 600px;
    margin: 0 auto;
}

.dashboard-card h2 {
    font-size: 1.5rem;
    color: #1a1a2e;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.dashboard-card > p {
    color: #6b7280;
    margin-bottom: 1.5rem;
}

.user-info {
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    margin-bottom: 1.75rem;
}

.user-info-row {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    align-items: center;
}

.user-info-row:last-child {
    border-bottom: none;
}

.user-info-label {
    font-weight: 600;
    color: #6b7280;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 130px;
}

.user-info-value {
    color: #1a1a2e;
    font-size: 0.95rem;
}

/* ============================================================
   Dashboard actions
   ============================================================ */
.dashboard-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ============================================================
   Admin Pages
   ============================================================ */
.admin-page {
    max-width: 1000px;
    margin: 0 auto;
}

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

.admin-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0;
}

/* ============================================================
   Data Table
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
    border-radius: 10px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
    font-size: 0.9rem;
}

.admin-table thead {
    background-color: #1a1a2e;
    color: #ffffff;
}

.admin-table th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.admin-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
}

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

.admin-table tbody tr:hover {
    background-color: #f9fafb;
}

.actions-cell {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    white-space: nowrap;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.badge-admin {
    background-color: #ede9fe;
    color: #5b21b6;
}

.badge-user {
    background-color: #e5e7eb;
    color: #374151;
}

/* ============================================================
   Small buttons & form helpers
   ============================================================ */
.btn-sm {
    padding: 0.35rem 0.85rem;
    font-size: 0.825rem;
    border-radius: 5px;
}

.inline-form {
    display: inline;
    margin: 0;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500 !important;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.text-muted {
    color: #9ca3af;
    font-size: 0.85rem;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .card,
    .dashboard-card {
        padding: 1.5rem 1.25rem;
        border-radius: 8px;
    }

    .nav-links a {
        padding: 0.35rem 0.5rem;
        font-size: 0.875rem;
    }

    .user-info-row {
        flex-direction: column;
        gap: 0.2rem;
    }
}

/* ============================================================
   Dashboard Page — card grid layout
   ============================================================ */
.dashboard-page {
    max-width: 1000px;
    margin: 0 auto;
}

.dashboard-welcome {
    margin-bottom: 2rem;
}

.dashboard-welcome h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 0.25rem;
}

.dashboard-welcome p {
    color: #6b7280;
    font-size: 1rem;
}

.cards-section {
    margin-bottom: 2.5rem;
}

.cards-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.875rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 1rem;
}

.nav-card {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: #ffffff;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
    text-decoration: none;
    border: 2px solid #e5e7eb;
    min-height: 100px;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.nav-card:hover {
    border-color: #4f46e5;
    box-shadow: 0 4px 16px rgba(79, 70, 229, 0.12);
    text-decoration: none;
    transform: translateY(-2px);
}

.nav-card:active {
    transform: scale(0.98);
}

.nav-card-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 0.2rem;
}

.nav-card-desc {
    font-size: 0.8rem;
    color: #9ca3af;
}

.nav-card-device {
    border-left: 3px solid #4f46e5;
}

.no-data-msg {
    color: #6b7280;
    font-size: 0.95rem;
    padding: 0.25rem 0;
}

/* ============================================================
   Model Group Form
   ============================================================ */
.model-form-page {
    max-width: 900px;
    margin: 0 auto;
}

.param-section {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
    padding: 1.5rem;
}

.param-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.param-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1a1a2e;
}

.param-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.param-row {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.875rem 1rem;
}

.param-row-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

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

.param-field-id     { flex: 0 0 80px;  min-width: 70px; }
.param-field-name   { flex: 1 1 160px; min-width: 120px; }
.param-field-type   { flex: 0 0 120px; min-width: 100px; }
.param-field-minmax { flex: 0 0 100px; min-width: 80px; }
.param-field-remove { flex: 0 0 auto; }

.param-field label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.3rem;
}

.param-field input,
.param-field select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #1a1a2e;
    background-color: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    box-sizing: border-box;
}

.param-field input:focus,
.param-field select:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.param-remove-btn {
    background: none;
    border: 1.5px solid #fca5a5;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.9rem;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.param-remove-btn:hover {
    background-color: #fee2e2;
    border-color: #ef4444;
}

.param-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
    padding: 1.25rem;
    border: 1.5px dashed #d1d5db;
    border-radius: 8px;
    margin: 0;
}

@media (max-width: 640px) {
    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .param-field-id,
    .param-field-type,
    .param-field-minmax {
        flex: 1 1 80px;
    }
}

/* ── Sortable table ─────────────────────────────────────────── */
.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.sort-link:hover {
    color: #4f46e5;
}

.sort-indicator {
    font-size: 0.7rem;
    color: #4f46e5;
}

/* ── Select inputs ──────────────────────────────────────────── */
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    background-color: #fff;
    color: #111827;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group select:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-group.has-error select {
    border-color: #ef4444;
}

/* ── Form textarea ──────────────────────────────────────────── */
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group textarea:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ── Permission group form ──────────────────────────────────── */
.pg-params-section {
    margin-top: 2rem;
}

.pg-params-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.pg-params-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.pg-filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pg-filter-bar label {
    font-size: 0.875rem;
    color: #6b7280;
    white-space: nowrap;
}

.pg-filter-bar select {
    padding: 0.35rem 2rem 0.35rem 0.6rem;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    background-color: #fff;
    color: #111827;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    cursor: pointer;
}

/* Parameter selection table */
.param-select-table .col-include {
    width: 64px;
    text-align: center;
}

.param-select-table .param-include {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #4f46e5;
}

.param-select-table .param-access-sel {
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.85rem;
    min-width: 110px;
    cursor: pointer;
}

.param-select-table tr.row-unchecked td {
    color: #9ca3af;
    opacity: 0.6;
}

/* ── Device checklist (user form) ───────────────────────────── */
.device-checklist {
    max-height: 220px;
    overflow-y: auto;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    padding: 0.4rem;
    background: #fff;
}

.device-check-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}

.device-check-item:hover {
    background-color: #f3f4f6;
}

.device-check-item input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: #4f46e5;
}

.device-check-item span {
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.4;
}

.text-muted {
    color: #6b7280;
}
