/* ============================================================
   Control Panel v2 - Senda Insular
   Login + Admin styles (same visual as original)
   ============================================================ */

:root {
    --cyan:         #2BBCD4;
    --cyan-dark:    #22a8be;
    --cyan-light:   #d6f4f9;
    --dark:         #1a2332;
    --darker:       #151d29;
    --bg:           #f0f2f4;
    --white:        #ffffff;
    --text:         #1f2937;
    --subtext:      #6b7280;
    --muted:        #9ca3af;
    --border:       #e5e7eb;
    --error:        #ef4444;
    --ok:           #10b981;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== HEADER ==================== */
.header {
    background: linear-gradient(180deg, #1e1e1e 0%, #2a2a2a 100%);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 0 rgba(43, 188, 212, 0.15), 0 4px 24px rgba(0, 0, 0, 0.25);
}

.header-logo-link { display: flex; align-items: center; }
.header-logo { height: 36px; width: auto; display: block; filter: brightness(0) invert(1); }

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}
.crumb {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: color 0.2s;
}
.crumb:hover:not(.crumb-current) { color: var(--cyan); }
.crumb-current { color: #fff; font-weight: 600; }
.crumb-sep { color: rgba(255, 255, 255, 0.4); font-size: 14px; }

.header-right { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.user-info { color: var(--cyan); font-size: 0.85rem; font-weight: 600; }
.header-sep { width: 1px; height: 24px; background: rgba(255,255,255,0.15); margin: 0 4px; }

.btn-header {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 12px;
    padding: 6px 14px;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-header:hover { color: #fff; border-color: rgba(255,255,255,0.6); }
.btn-logout:hover { color: var(--error); border-color: var(--error); }

/* ==================== HERO ==================== */
.hero {
    background: linear-gradient(135deg, var(--darker) 0%, #0f2a33 100%);
    border-bottom: 2px solid var(--cyan);
    padding: 2.5rem 2rem 2rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(600px 300px at 20% 120%, rgba(43, 188, 212, 0.22), transparent 60%),
        radial-gradient(400px 200px at 80% -40px, rgba(43, 188, 212, 0.14), transparent 60%);
    pointer-events: none;
}

.hero h1 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; color: #ffffff; position: relative; z-index: 1; letter-spacing: 0.02em; margin-bottom: 0.6rem; }
.hero p { font-size: 0.95rem; color: rgba(255,255,255,0.75); margin-top: 0.5rem; position: relative; z-index: 1; max-width: 640px; margin-left: auto; margin-right: auto; }

/* ==================== APPS GRID ==================== */
.apps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 2.5rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
    align-content: start;
}

@media (max-width: 1024px) {
    .apps-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .apps-grid { grid-template-columns: 1fr; padding: 1.5rem 1rem; gap: 1rem; }
}

.app-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem 2rem 2rem;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
    transition: border-color 0.24s, box-shadow 0.24s, transform 0.24s;
    cursor: pointer;
}

.app-card:hover {
    border-color: var(--cyan);
    box-shadow: 0 12px 24px -6px rgba(43, 188, 212, 0.15), 0 6px 12px -4px rgba(17, 24, 39, 0.06);
    transform: translateY(-3px);
}

.app-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.app-card h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.app-card p {
    font-size: 0.85rem;
    color: var(--subtext);
    line-height: 1.5;
    margin: 0;
    flex: 1;
}

.app-link {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--cyan);
    margin-top: 0.75rem;
}

.app-card:hover .app-link { color: var(--cyan-dark); }

/* No apps message */
.no-apps-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 2rem;
    color: var(--subtext);
}
.no-apps-message p { font-size: 1.1rem; font-weight: 600; color: var(--text); }
.no-apps-sub { font-size: 0.9rem; color: var(--muted); margin-top: 0.5rem; }

/* ==================== LOGIN PAGE ==================== */
.login-page {
    background: linear-gradient(135deg, var(--darker) 0%, #0f2a33 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-page::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(800px 400px at 30% 80%, rgba(43, 188, 212, 0.15), transparent 60%),
        radial-gradient(600px 300px at 70% 20%, rgba(43, 188, 212, 0.1), transparent 60%);
    pointer-events: none;
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.login-card {
    background: var(--white);
    border-radius: 18px;
    padding: 2.5rem 2rem;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: 1px;
}

.login-header p {
    font-size: 0.9rem;
    color: var(--subtext);
    margin-top: 0.25rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--subtext);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(43, 188, 212, 0.12);
}

.form-error {
    color: var(--error);
    font-size: 0.82rem;
    min-height: 1.2em;
    margin-bottom: 0.75rem;
}

.btn-login {
    width: 100%;
    padding: 0.875rem;
    background: var(--cyan);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px -2px rgba(43, 188, 212, 0.4);
}

.btn-login:hover {
    background: var(--cyan-dark);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px -4px rgba(43, 188, 212, 0.5);
}

.btn-login:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.4);
}

/* ==================== ADMIN ==================== */
.admin-content {
    padding: 2rem;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

.admin-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
}

.admin-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

/* Form layout */
.form-row-simple {
    display: grid;
    grid-template-columns: 1fr 1fr 140px;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-field label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--subtext);
    letter-spacing: 0.3px;
}

.form-field input, .form-field select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-field input:focus, .form-field select:focus {
    outline: none;
    border-color: var(--cyan);
    box-shadow: 0 0 0 2px rgba(43, 188, 212, 0.1);
}

.form-field input[readonly] {
    background: #f9fafb;
    color: var(--subtext);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}

/* Permissions table section */
.perms-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.perms-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.perms-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.perms-table thead tr {
    background: var(--bg);
}

.perms-table th {
    padding: 0.6rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--subtext);
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.perms-table th.perms-app-col {
    text-align: left;
    width: 50%;
}

.perms-table th.perms-check-col {
    width: 25%;
}

.check-col-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--subtext);
}

.check-col-header input[type="checkbox"] {
    accent-color: var(--cyan);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.perms-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f0f2f4;
}

.perms-table td.perms-app-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

.perms-table td.perms-check-cell {
    text-align: center;
}

.perms-table td.perms-check-cell input[type="checkbox"] {
    accent-color: var(--cyan);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

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

.perms-table tr:hover td {
    background: rgba(43, 188, 212, 0.03);
}

/* Permission badges in users table */
.perms-cell {
    max-width: 260px;
}

.perm-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin: 1px 2px;
    white-space: nowrap;
}

.perm-badge small {
    opacity: 0.7;
    font-weight: 500;
}

.perm-all { background: #fef3c7; color: #92400e; }
.perm-writer { background: var(--cyan-light); color: var(--cyan-dark); }
.perm-reader { background: #f3e8ff; color: #6b21a8; }
.perm-none { background: #f3f4f6; color: var(--muted); }

/* Actions cell */
.actions-cell {
    white-space: nowrap;
}

.actions-cell .btn {
    margin: 1px;
}

/* Users table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    background: var(--bg);
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--subtext);
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    border-bottom: 1px solid #f0f2f4;
    vertical-align: middle;
}

.row-inactive { opacity: 0.5; }

.role-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
}
.role-admin { background: #fef3c7; color: #92400e; }
.role-user { background: var(--cyan-light); color: var(--cyan-dark); }

.status-active { color: var(--ok); font-weight: 600; font-size: 0.8rem; }
.status-inactive { color: var(--muted); font-size: 0.8rem; }

.form-message { font-size: 0.82rem; margin-top: 0.75rem; }
.form-message.success { color: var(--ok); }
.form-message.error { color: var(--error); }

/* ==================== BUTTONS ==================== */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-primary { background: var(--cyan); color: var(--white); }
.btn-primary:hover { background: var(--cyan-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: none; color: var(--error); border: 1px solid var(--error); }
.btn-danger:hover { background: #fee2e2; }
.btn-delete { background: none; color: #991b1b; border: 1px solid #991b1b; }
.btn-delete:hover { background: #fee2e2; color: #7f1d1d; }
.btn-edit { background: none; color: var(--cyan-dark); border: 1px solid var(--cyan); }
.btn-edit:hover { background: var(--cyan-light); }
.btn-ok { background: none; color: var(--ok); border: 1px solid var(--ok); }
.btn-ok:hover { background: #d1fae5; }
.btn-test { background: none; color: #7c3aed; border: 1px solid #7c3aed; }
.btn-test:hover { background: #f3e8ff; }
.btn-sm { padding: 4px 8px; font-size: 0.72rem; }

/* ==================== FOOTER ==================== */
.footer {
    padding: 1.25rem 2rem;
    text-align: center;
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: auto;
    background: linear-gradient(180deg, #2a2a2a 0%, #1e1e1e 100%);
    box-shadow: 0 -1px 0 rgba(43, 188, 212, 0.1);
}

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

@media (max-width: 768px) {
    .header { padding: 0 1rem; gap: 0.8rem; }
    .header-logo { height: 28px; }
    .breadcrumbs { font-size: 12px; }
    .header-right { gap: 0.5rem; }
    .btn-header { padding: 5px 8px; font-size: 0.72rem; }
    .user-info { font-size: 0.78rem; }

    .admin-content { padding: 1rem; }
    .admin-card { padding: 1rem; }
    .form-row-simple { grid-template-columns: 1fr; }

    .admin-table { font-size: 0.78rem; }
    .admin-table th, .admin-table td { padding: 0.5rem; }
    .admin-table .perms-cell { max-width: 140px; }
    .actions-cell { display: flex; flex-direction: column; gap: 2px; }

    .perms-table { font-size: 0.8rem; }

    .footer { padding: 1rem; }
}

@media (max-width: 480px) {
    .header { height: 56px; padding: 0 0.75rem; gap: 0.5rem; }
    .header-logo { height: 24px; }
    .breadcrumbs { display: none; }
    .header-right .btn-header:not(.btn-logout) { display: none; }

    .login-container { padding: 1rem; }
    .login-card { padding: 1.75rem 1.25rem; }
    .login-header h1 { font-size: 1rem; }

    .admin-table { display: block; overflow-x: auto; }
    .perm-badge { font-size: 0.6rem; padding: 1px 4px; }
    .check-col-header { font-size: 0.6rem; }

    .footer { font-size: 0.72rem; }
}
