:root
{
    --primary: #FF8F00;
    --primary-light: #FFCA28;
    --primary-dark: #D84315;
    --secondary: #E65100;
    --accent: #FFC107;
    --bg: #F5F5F5;
    --bg-card: #FFFFFF;
    --text: #212121;
    --text-light: #757575;
    --border: #E0E0E0;
    --danger: #D32F2F;
    --success: #388E3C;
    --warning: #F57C00;
}

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

html
{
    overflow: auto !important;
}

body
{
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg) url('../RESOURCES/bg_hive.svg') no-repeat center center / cover;
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 72px;
}

/* Safari ignores padding-bottom on body — use a real block element instead */
body::after
{
    content: '';
    display: block;
    height: 72px;
}

#header
{
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 8px 24px 8px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 1rem;
    z-index: 100;
    margin: 1rem 1rem 0;
    border-radius: 12px;
}

#header #title
{
    font-size: 1.6em;
    font-weight: 600;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#header #headerUser
{
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#header #userInfo
{
    font-size: 0.9em;
    opacity: 0.9;
}

#header #userRoles
{
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 3px;
}

#header .role-badge
{
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.6em;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.9);
}

.title-content
{
    display: flex;
    align-items: center;
    gap: 5px;
}

.version-badge
{
    display: none;
}

#logo_hive
{
    display: block;
    margin: 0px auto;
    max-width: 180px;
    height: auto;
}

#header .header-logo
{
    height: 44px;
    width: 44px;
    border-radius: 4px;
    flex-shrink: 0;
    cursor: pointer;
}

.content
{
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 24px 24px;
}

/* CARDS */

.card
{
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.card .card-title
{
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-dark);
}

/* STAT CARDS */

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

.stat-card
{
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover
{
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.stat-card .stat-value
{
    font-size: 2em;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label
{
    font-size: 0.85em;
    color: var(--text-light);
    margin-top: 4px;
}

.stat-card .stat-icon
{
    font-size: 1.5em;
    color: var(--primary-light);
    margin-bottom: 8px;
}

/* TABLES */

table.data-table
{
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

table.data-table thead
{
    background: var(--primary);
    color: white;
}

table.data-table th
{
    padding: 8px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

table.data-table td
{
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

table.data-table td.num
{
    text-align: right;
    white-space: nowrap;
}

table.data-table tbody tr:hover
{
    background: #FFF8E1;
}

table.data-table th .th-btn
{
    width: 100%;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 1em;
    padding: 4px 0 !important;
}

/* FORMS */

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

.form-group label
{
    display: block;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea
{
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus
{
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255,143,0,0.15);
}

/* BUTTON DEFAULTS */

button
{
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85em;
}

table button
{
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.82em;
}

/* NAV BUTTONS */

.nav-grid
{
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 24px 0;
}

.nav-grid button
{
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}

.nav-grid button i
{
    font-size: 1.5em;
    color: var(--primary);
}

.nav-grid button:hover
{
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

/* VISIBILITY */

body:not(.LOGGED_IN) .requires-login {display:none;}
body.LOGGED_IN .requires-logout {display:none;}

/* BACK BUTTON */

button.back-nav
{
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 200;
    background: var(--primary);
    color: white;
    border: 2px solid var(--primary);
    border-radius: 12px;
    height: 48px;
    padding: 0 20px;
    font-size: 0.85em;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: background 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

button.back-nav:hover
{
    background: white;
    color: var(--primary);
    transform: translateY(-1px);
}

button.back-nav i
{
    font-size: 1.15em;
}

.back-nav-group
{
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 200;
    display: flex;
    gap: 8px;
}

.back-nav-group button.back-nav
{
    position: static;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

button.back-nav.back-nav-orange
{
    background: #E65100;
    border-color: #E65100;
}

button.back-nav.back-nav-orange:hover
{
    background: white;
    color: #E65100;
}

/* PAGINATION */

.pagination-bar
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    font-size: 0.85em;
    color: var(--text-light);
}

.pagination-controls
{
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-page
{
    min-width: 60px;
    text-align: center;
    font-weight: 600;
    color: var(--text);
}

.pagination-btn
{
    padding: 4px 10px !important;
    font-size: 0.9em !important;
}

.pagination-btn:disabled
{
    opacity: 0.35;
    cursor: default;
}

.pagination-size
{
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-size select
{
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95em;
    font-family: inherit;
}

/* BADGES */

.badge
{
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.badge-success {background: #E8F5E9; color: var(--success);}
.badge-warning {background: #FFF3E0; color: var(--warning);}
.badge-danger {background: #FFEBEE; color: var(--danger);}
.badge-info {background: #E3F2FD; color: #1976D2;}
.badge-success::before { content: "\2713 "; }
.badge-danger::before { content: "\2717 "; }
.badge-warning::before { content: "\26A0 "; }

/* TOOLBAR */

.toolbar
{
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar-card
{
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.toolbar-card .toolbar
{
    margin-bottom: 0;
}

/* FILTER BOX */

.filter-box
{
    display: flex;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.filter-box .form-group
{
    flex: 1;
    margin-bottom: 0;
}

.filter-box .form-group label
{
    font-size: 0.75em;
    margin-bottom: 2px;
}

.filter-box .form-group input,
.filter-box .form-group select
{
    padding: 6px 10px;
    font-size: 0.85em;
}

/* TOOLBAR SPACER */

.toolbar-spacer
{
    flex: 1;
}

/* DETAIL GRID */

.detail-grid
{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.detail-item
{
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-item label
{
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-item span
{
    font-size: 0.95em;
    color: var(--text);
    word-break: break-word;
}

/* FORM ROWS */

.form-row
{
    display: flex;
    gap: 12px;
    margin-bottom: 0;
}

.form-row .form-group
{
    flex: 1;
}

/* DIALOG OVERLAY */

.dialog-overlay
{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.dialog
{
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.dialog .dialog-title
{
    font-size: 1.2em;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-light);
}

.dialog .dialog-buttons
{
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* TABLE ACTIONS — minimum width */

th:last-child,
td.actions,
th.col-actions
{
    width: 1%;
    white-space: nowrap;
    padding-left: 6px;
    padding-right: 6px;
}

td.actions button
{
    margin-right: 4px;
}

/* TABLE ID COLUMNS — minimum width, right-aligned */

td.col-id,
th.col-id
{
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

/* TABLE BADGE CELLS — minimum width */

td.col-status,
th.col-status
{
    width: 1%;
    white-space: nowrap;
}

td.col-date,
th.col-date
{
    width: 1%;
    white-space: nowrap;
}

td.col-email,
th.col-email,
td.col-phone,
th.col-phone
{
    width: 1%;
    white-space: nowrap;
}

/* OVERRIDE KATANA BUTTON COLORS */

ki-button.ACCEPT,
button.ACCEPT
{
    --bg-color: var(--success) !important;
}

/* hover gestito dal base Katana (swap fg/bg) */

/* TOGGLE BUTTON (two-state active/inactive) */

.toggle-btn
{
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s, transform 0.1s;
    font-family: inherit;
    color: white;
}

.toggle-btn:hover
{
    transform: translateY(-1px);
}

.toggle-btn.active
{
    background: var(--success);
    border-color: var(--success);
}

.toggle-btn.active:hover
{
    background: white;
    color: var(--success);
}

.toggle-btn.inactive
{
    background: var(--danger);
    border-color: var(--danger);
}

.toggle-btn.inactive:hover
{
    background: white;
    color: var(--danger);
}

/* RESPONSIVE */

@media (max-width: 768px)
{
    #header {padding: 10px 13px; margin: 0.5rem 0.5rem 0; border-radius: 10px;}
    #header #title {font-size: 0.76em;}
    #header .header-logo {height: 27px; width: 27px;}
    .content {padding: 12px 16px 80px;}
    .stats-grid {grid-template-columns: repeat(2, 1fr);}
    .nav-grid {grid-template-columns: repeat(2, 1fr); font-size: 0.88em;}
    .nav-grid button {padding: 12px;}
    .nav-grid button i {font-size: 1.3em;}

    table.data-table {display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;}
    .filter-box {flex-direction: column;}
    .detail-grid {grid-template-columns: repeat(2, 1fr);}
    .toolbar {flex-direction: column; align-items: stretch;}
    .form-row {flex-direction: column; gap: 0;}
    .dialog {max-width: 100%; margin: 8px;}
    .pagination-bar {flex-direction: column; gap: 8px; align-items: center;}
    button.back-nav {height: 42px; padding: 0 16px; bottom: 16px; left: 16px; font-size: 0.78em; gap: 6px;}
    .back-nav-group {bottom: 16px; left: 16px;}
    body {padding-bottom: 58px;}
    body::after {height: 58px;}
}

@media (max-width: 480px)
{
    #header {padding: 10px 14px; margin: 0.5rem 0.5rem 0;}
    #header #title {font-size: 0.65em;}
    .content {padding: 12px 12px 80px;}
    .stats-grid {grid-template-columns: 1fr;}
    .nav-grid {grid-template-columns: 1fr;}
    .detail-grid {grid-template-columns: 1fr;}
    .dialog-overlay {padding: 8px;}
    table.data-table th, table.data-table td {padding: 6px 8px; font-size: 0.85em;}
}

/* ========== HIVE DIALOG SYSTEM ========== */

.hive-dialog-overlay
{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: hive-dialog-fadein 0.2s ease-out;
}

.hive-dialog
{
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: hive-dialog-slidein 0.2s ease-out;
}

.hive-dialog-title
{
    font-size: 1.15em;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-light);
}

.hive-dialog-title i
{
    margin-right: 6px;
}

.hive-debug-icon
{
    cursor: pointer;
    color: var(--warning, #FF8F00);
    transition: transform 0.15s ease;
}

.hive-debug-icon:hover
{
    transform: scale(1.3);
}

/* ========== API DEBUG INFO PANEL ========== */

.hive-debug-info
{
    background: var(--bg-light, #f5f5f5);
    border: 1px solid var(--border, #ddd);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    font-size: 0.82em;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    color: var(--text, #333);
    max-height: 300px;
    overflow-y: auto;
}

.hive-debug-row
{
    padding: 3px 0;
    word-break: break-all;
}

.hive-debug-label
{
    font-weight: 700;
    color: var(--primary-dark, #E65100);
    margin-right: 4px;
}

.hive-debug-pre
{
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #ddd);
    border-radius: 4px;
    padding: 8px;
    margin: 4px 0 8px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.95em;
}

.hive-dialog-message
{
    padding: 4px 0 16px;
    color: var(--text);
    line-height: 1.5;
    word-break: break-word;
}

.hive-dialog-input
{
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    transition: border-color 0.2s;
    box-sizing: border-box;
    margin-bottom: 8px;
}

.hive-dialog-input:focus
{
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255,143,0,0.15);
}

.hive-dialog-buttons
{
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.hive-dialog-btn
{
    padding: 8px 18px;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s, transform 0.1s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.hive-dialog-btn:hover
{
    transform: translateY(-1px);
}

.hive-dialog-btn:active
{
    transform: translateY(0);
}

.hive-dialog-btn-accept
{
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.hive-dialog-btn-accept:hover
{
    background: white;
    color: var(--success);
}

.hive-dialog-btn-cancel
{
    background: #757575;
    color: white;
    border-color: #757575;
}

.hive-dialog-btn-cancel:hover
{
    background: white;
    color: #757575;
}

.hive-dialog-btn-success
{
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.hive-dialog-btn-success:hover
{
    background: white;
    color: var(--success);
}

.hive-dialog-btn-danger
{
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.hive-dialog-btn-danger:hover
{
    background: white;
    color: var(--danger);
}

@keyframes hive-dialog-fadein
{
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes hive-dialog-slidein
{
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px)
{
    .hive-dialog-overlay { padding: 12px; }
    .hive-dialog { padding: 16px; }
}

@media print
{
    .hive-dialog-overlay { display: none !important; }
}

/* ========== QR SCANNER VIDEO + FRAME ========== */

.qr-video-wrapper
{
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 500px;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--primary);
}

.qr-video-wrapper video
{
    display: block;
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
}

.qr-scan-frame
{
    position: absolute;
    top: 50%;
    left: 50%;
    width: 55%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border: 3px solid rgba(255, 255, 255, 0.85);
    border-radius: 16px;
    box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
}

.qr-scan-frame::after
{
    content: '';
    position: absolute;
    left: 8%;
    right: 8%;
    height: 2px;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary);
    opacity: 0.9;
    animation: qr-scan-sweep 2s ease-in-out infinite;
}

@keyframes qr-scan-sweep
{
    0%, 100% { top: 8%; }
    50%      { top: 92%; }
}

/* ========== CREDITS DIALOG ========== */

.hive-credits-dialog
{
    background: white;
    border-radius: 16px;
    padding: 40px 48px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: hive-dialog-slidein 0.2s ease-out;
    max-width: 340px;
    width: 100%;
}

.hive-credits-logo
{
    width: 80px;
    height: 80px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.hive-credits-name
{
    font-size: 1.6em;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 4px;
}

.hive-credits-version
{
    font-size: 0.85em;
    color: var(--text-light);
    font-family: monospace;
    margin-bottom: 20px;
}

.hive-credits-dev
{
    font-size: 0.9em;
    color: #555;
    margin-bottom: 16px;
}

.hive-credits-dps-logo
{
    height: 56px;
    opacity: 0.7;
}

:focus-visible
{
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.balance-positive { color: var(--success); }
.balance-negative { color: var(--danger); }
