/* ===== VARIABLES ===== */
:root {
    --bg: #f5f6f8;
    --bg-card: #ffffff;
    --bg-nav: #1a1f2e;
    --bg-nav-hover: #252b3d;
    --text: #2d3142;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --text-nav: #c8ccd4;
    --text-nav-active: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff4ff;
    --accent: #0891b2;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --border: #e5e7eb;
    --border-focus: #93c5fd;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --radius: 8px;
    --radius-sm: 5px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'DM Mono', 'SF Mono', 'Fira Code', monospace;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== NAVBAR ===== */
.navbar {
    background: var(--bg-nav);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav-brand {
    display: flex;
    align-items: center;
    margin-right: 2.5rem;
    text-decoration: none;
}

.nav-logo-img { height: 28px; width: auto; }

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

.nav-link {
    color: var(--text-nav);
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.nav-link:hover { background: var(--bg-nav-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-left: auto;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.nav-username { color: var(--text-nav); font-size: 0.85rem; }
.logout-link { color: var(--text-light) !important; font-size: 0.85rem; }

/* Dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.3rem;
    background: var(--bg-nav);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 200;
    padding: 0.3rem;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.dropdown-item {
    display: block;
    padding: 0.5rem 0.8rem;
    color: var(--text-nav);
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.1s;
}
.dropdown-item:hover { background: var(--bg-nav-hover); color: #fff; text-decoration: none; }
.dropdown-item.active { color: var(--primary); }
.dropdown-arrow { opacity: 0.6; }

/* ===== BADGES & TAGS ===== */
.badge-admin {
    background: #7c3aed;
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.badge-standard {
    background: #6b7280;
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge {
    background: var(--border);
    color: var(--text-muted);
    padding: 0.1rem 0.55rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.3rem;
}

.tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}
.tag-cliente { background: #dbeafe; color: #1e40af; }
.tag-fornitore { background: #fef3c7; color: #92400e; }

/* ===== CONTAINER ===== */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.2rem;
}
.page-header h2 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.header-stats { color: var(--text-muted); font-size: 0.85rem; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.15s;
}
.back-link:hover { color: var(--primary); text-decoration: none; }

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.2rem;
}

.search-form { flex: 1; min-width: 280px; }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-icon {
    position: absolute;
    left: 0.75rem;
    width: 18px;
    height: 18px;
    color: var(--text-light);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 0.6rem 0.75rem 0.6rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    background: var(--bg-card);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.search-clear {
    position: absolute;
    right: 0.6rem;
    color: var(--text-light);
    font-size: 1.2rem;
    cursor: pointer;
    text-decoration: none;
}

.filter-tabs { display: flex; gap: 0.3rem; }
.filter-tab {
    padding: 0.45rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: all 0.15s;
    text-decoration: none;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.filter-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.filter-tab .badge { font-size: 0.7rem; }
.filter-tab.active .badge { background: rgba(255,255,255,0.25); color: #fff; }

/* ===== TABLE ===== */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.data-table thead { border-bottom: 2px solid var(--border); }
.data-table th {
    text-align: left;
    padding: 0.7rem 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.data-table td {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--primary-light); }

.data-table-compact th { padding: 0.5rem 0.7rem; }
.data-table-compact td { padding: 0.45rem 0.7rem; }

.clickable-row { cursor: pointer; transition: background 0.1s; }
.name-cell strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 0.84rem; letter-spacing: 0.02em; }
.row-disabled { opacity: 0.5; }
.actions-cell { white-space: nowrap; }

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 1rem;
    justify-content: center;
}
.page-link {
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.15s;
}
.page-link:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-info { color: var(--text-light); font-size: 0.8rem; margin-left: 0.5rem; }

/* ===== DETAIL PAGE ===== */
.detail-page { margin-top: 0.5rem; }

.detail-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}
.detail-title-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}
.detail-title-row h2 { font-size: 1.5rem; }
.detail-tags { display: flex; gap: 0.4rem; }
.detail-code { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.2rem; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.detail-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.2rem;
}
.detail-card.full-width {
    grid-column: 1 / -1;
    margin-bottom: 0.5rem;
}
.detail-card h3 {
    font-size: 0.88rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.9rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.detail-fields { display: flex; flex-direction: column; gap: 0.5rem; }
.field-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.25rem 0;
}
.field-label {
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 500;
    min-width: 130px;
    flex-shrink: 0;
}
.field-value {
    text-align: right;
    font-weight: 500;
    word-break: break-word;
}
.field-link { color: var(--primary); }
.field-link:hover { text-decoration: underline; }
.note-text { color: var(--text); font-size: 0.9rem; line-height: 1.7; }

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-group input[readonly] { background: var(--bg); color: var(--text-muted); }

.radio-group, .checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.radio-label, .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.form-actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-card);
    color: var(--text);
    text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--bg); }
.btn-secondary:hover { border-color: var(--text-light); }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-warn { color: var(--warning); border-color: var(--warning); background: transparent; }
.btn-warn:hover { background: var(--warning); color: #fff; }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

/* ===== ALERTS ===== */
.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 0.8rem; }

/* ===== STATUS ===== */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.3rem;
}
.status-active { background: var(--success); }
.status-inactive { background: var(--danger); }

/* ===== USERS LAYOUT ===== */
.users-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1rem;
    align-items: start;
}
@media (max-width: 900px) {
    .users-layout { grid-template-columns: 1fr; }
}

/* ===== LOGIN ===== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1f2e 0%, #2d3142 100%);
}

.login-container { width: 100%; max-width: 380px; padding: 1.5rem; }

.login-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-logo-img {
    height: 48px;
    width: auto;
    margin-bottom: 0.8rem;
}
.login-header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.login-subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 0.2rem;
}

.login-form .form-group { margin-bottom: 0.9rem; }
.login-form .btn { margin-top: 0.5rem; padding: 0.65rem; font-size: 0.95rem; }

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

/* ===== FOOTER ===== */
.footer {
    padding: 1.5rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border);
}
.footer-main { text-align: center; }
.footer-company {
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}
.footer-company a { color: var(--text-muted); }
.footer-company a:hover { color: var(--primary); }
.footer-links {
    font-size: 0.78rem;
    color: var(--text-light);
}
.footer-links a { color: var(--text-muted); }
.footer-links a:hover { color: var(--primary); }
.footer-sep { margin: 0 0.4rem; color: var(--border); }

/* ===== LOGIN LEGAL LINKS ===== */
.login-legal-link { color: rgba(255,255,255,0.4) !important; font-size: 0.78rem; }
.login-legal-link:hover { color: rgba(255,255,255,0.7) !important; }

/* ===== LEGAL PAGES ===== */
.legal-content { max-width: 800px; }
.legal-content .detail-card { margin-bottom: 0.8rem; }
.legal-content .detail-card h3 { color: var(--text); font-size: 0.95rem; }
.legal-content p { font-size: 0.9rem; line-height: 1.75; color: var(--text); margin-bottom: 0.6rem; }
.legal-content p:last-child { margin-bottom: 0; }
.legal-update { color: var(--text-light) !important; font-size: 0.82rem !important; font-style: italic; }

/* ===== AUDIT LOG ===== */
.audit-filters .filter-row {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    align-items: flex-end;
}
.audit-filters .form-group { flex: 1; min-width: 140px; margin-bottom: 0; }
.audit-filters .filter-actions { flex: 0; min-width: auto; }

.form-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    background: var(--bg-card);
    transition: border-color 0.15s;
}
.form-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input[type="date"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
}
input[type="date"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.audit-action {
    display: inline-block;
    padding: 0.12rem 0.5rem;
    border-radius: 4px;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.audit-login { background: #dbeafe; color: #1e40af; }
.audit-logout { background: #f3f4f6; color: #6b7280; }
.audit-view_contact { background: #ede9fe; color: #6d28d9; }
.audit-user_create { background: #d1fae5; color: #065f46; }
.audit-user_update { background: #fef3c7; color: #92400e; }
.audit-user_toggle { background: #ffedd5; color: #9a3412; }
.audit-user_delete { background: #fee2e2; color: #991b1b; }
.audit-search { background: #e0f2fe; color: #075985; }

.detail-cell { max-width: 350px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 0.8rem; }
    .nav-brand { margin-right: 1rem; }
    .container { padding: 1rem; }
    .toolbar { flex-direction: column; }
    .search-form { min-width: 100%; }
    .filter-tabs { width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
    .field-row { flex-direction: column; gap: 0.15rem; }
    .field-value { text-align: left; }
    .audit-filters .filter-row { flex-direction: column; }
    .audit-filters .form-group { min-width: 100%; }
}
