/**
 * Hostanno Invoicing - Materialize-style Admin Template
 * Built on Bootstrap 5, inspired by Pixinvent Materialize
 */
:root {
    --font-family: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-width: 260px;
    --navbar-height: 62px;
    --primary: rgb(10, 50, 108);
    --primary-hover: rgb(8, 40, 90);
    --primary-light: rgba(10, 50, 108, 0.12);
    --success: #28c76f;
    --success-light: #e8f9ef;
    --warning: #ff9f43;
    --warning-light: #fff5eb;
    --danger: #ea5455;
    --danger-light: #fef2f2;
    --bg-body: #f8f7fa;
    --bg-card: #fff;
    --text-primary: #5d5871;
    --text-secondary: #6e6b7b;
    --text-muted: #b9b9c3;
    --border-color: #ebe9f1;
    --shadow: 0 4px 24px -4px rgba(10, 50, 108, 0.08);
    --shadow-card: 0 4px 24px -4px rgba(10, 50, 108, 0.08), 0 0 2px 0 rgba(10, 50, 108, 0.06);
    --radius: 0.375rem;
    --input-height: 2.5rem;
}

* { box-sizing: border-box; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font-family);
    margin: 0;
    padding: 0;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Layout - Materialize structure */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.layout-navbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--navbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 50;
    box-shadow: 0 2px 6px rgba(10, 50, 108, 0.04);
}

.layout-menu {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    transition: transform 0.2s, box-shadow 0.2s;
}

/* Skrivanje scrollbara u sidebaru – svi preglednici */
.sidebar-no-scrollbar,
.sidebar-no-scrollbar .menu-nav-wrap,
.menu-nav-wrap {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.sidebar-no-scrollbar .menu-nav-wrap::-webkit-scrollbar,
.menu-nav-wrap::-webkit-scrollbar,
.menu-nav-wrap::-webkit-scrollbar-track,
.menu-nav-wrap::-webkit-scrollbar-thumb {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
    background: transparent !important;
}

.layout-page {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    min-height: calc(100vh - var(--navbar-height));
    padding: 1.5rem;
}

/* Sidebar / Menu – header fiksiran na vrhu, nav scrolla bez scrollbara */
.menu-header-fixed,
.menu-header {
    position: sticky;
    top: 0;
    height: var(--navbar-height);
    min-height: var(--navbar-height);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 10;
    background: var(--bg-card);
}

.menu-nav-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.menu-nav {
    padding: 0.75rem 0;
}

.menu-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.2rem;
    text-decoration: none;
    color: var(--text-primary);
}

.menu-brand:hover { text-decoration: none; color: var(--primary); }

.sidebar-logo-h {
    font-size: 2.25rem;
    line-height: 1;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.05em;
    margin-right: -0.1rem;
}

.sidebar-brand-words {
    display: flex;
    flex-direction: column;
    gap: 0;
    line-height: 1.1;
}

.sidebar-brand-invoicing {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: lowercase;
}

.sidebar-brand-ostanno {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: lowercase;
    letter-spacing: -0.02em;
}

.sidebar-app-logo {
    height: 50px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    display: block;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    margin: 0 0.5rem;
    border-radius: var(--radius);
}

.menu-item:hover {
    background: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}

.menu-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 1rem;
}

.menu-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #6b7280);
    padding: 0.75rem 1.25rem 0.35rem;
    margin: 0 0.5rem;
}

/* Navbar */
.navbar-brand-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-menu-wrapper { position: relative; }

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
}

.user-menu:hover { background: var(--bg-body); }

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #9e95f5);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-name { font-weight: 600; font-size: 0.9375rem; color: var(--text-primary); }
.user-role { font-size: 0.75rem; color: var(--text-secondary); }

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 200px;
    z-index: 200;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.dropdown-item:hover {
    background: var(--bg-body);
    text-decoration: none;
    color: var(--primary);
}

.dropdown-item-danger:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

/* Content */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

/* Cards - Materialize style */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.card-body {
    padding: 1.5rem;
}

/* Stats cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stat-card-gray-light { border-left: 4px solid #d1d0d7; }
.stat-card-gray-dark { border-left: 4px solid #6e6b7b; }
.stat-card-warning { border-left: 4px solid var(--warning); }
.stat-card-success { border-left: 4px solid var(--success); }
.stat-card-info { border-left: 4px solid var(--primary); }

.dashboard-sections {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dashboard-sections .card {
    width: 100%;
}

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.form-control,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="search"],
select,
textarea {
    font-family: var(--font-family);
    font-size: 0.9375rem;
    height: var(--input-height);
    padding: 0 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

textarea {
    height: auto;
    min-height: 100px;
    padding: 0.875rem;
    resize: vertical;
}

.file-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}

.file-input-wrap .btn {
    margin: 0;
    cursor: pointer;
}

.file-input-name {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Proizvodi u ugovoru: proizvod što šire, ostala polja samo koliko treba */
.form-row.contract-product {
    grid-template-columns: 1fr auto auto auto auto;
    align-items: end;
    margin-bottom: 0.5rem;
}

/* Ostala polja ne rastežu se – širina po sadržaju */
.form-row.contract-product .form-group:not(:first-child) {
    min-width: 0;
    width: max-content;
}
.form-row.contract-product .form-group:last-child {
    width: auto;
}

.form-row.contract-product .form-group {
    margin-bottom: 0;
}

.form-row.contract-product .form-group:first-child {
    min-width: 0; /* da 1fr može da se smanji po potrebi */
}

/* Dugme za uklanjanje reda – u liniji sa inputima */
.form-row.contract-product .form-group-remove {
    display: flex;
    align-items: flex-end;
}

.form-row.contract-product .btn-icon.rm-prod {
    height: var(--input-height);
    width: 2.25rem;
    flex-shrink: 0;
}

/* Stavke na fakturi: proizvod/naziv zauzima sav preostali prostor, ostalo po potrebi */
.form-row.invoice-item {
    display: grid;
    grid-template-columns: 1fr 80px 100px 80px 40px;
    align-items: end;
    margin-bottom: 0.5rem;
    gap: 0.75rem;
}
.form-row.invoice-item .form-group {
    margin-bottom: 0;
}
.form-row.invoice-item .form-group:first-child {
    min-width: 0;
}

.form-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236e6b7b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.search-box { max-width: 280px; }

/* Buttons - Materialize style */
.btn {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 0.9375rem;
    padding: 0.5rem 1.125rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    text-decoration: none;
    height: var(--input-height);
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 8px -2px rgba(115, 103, 240, 0.4);
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: white;
    box-shadow: 0 6px 12px -2px rgba(115, 103, 240, 0.5);
}

.btn-secondary { background: var(--text-secondary); color: white; }
.btn-secondary:hover { background: #5a5772; color: white; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-body);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-danger { background: #4a4a4a; color: white; border-color: #4a4a4a; }
.btn-danger:hover { background: #3d3d3d; color: white; border-color: #3d3d3d; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #24b263; color: white; }

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
    height: auto;
}

/* Tables */
.table-responsive { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.table th,
.table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr:hover {
    background: rgba(115, 103, 240, 0.04);
}

.table-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.table-actions .btn {
    height: auto;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.page-header .table-actions .btn {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

td.table-actions {
    vertical-align: middle;
}

.btn-icon {
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    text-align: center;
    vertical-align: middle;
}


.btn-icon:hover {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.btn-icon.btn-primary {
    color: var(--primary);
}

.btn-icon.btn-primary:hover {
    color: var(--primary-hover);
}

.btn-icon.btn-danger {
    color: #4a4a4a;
}

.btn-icon.btn-danger:hover {
    color: var(--danger);
}

.btn-icon svg {
    display: block;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    flex-shrink: 0;
    margin: auto;
}

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9375rem;
}

.alert-success { background: var(--success-light); color: #1a7f37; border: 1px solid #a7f3d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
}

.badge-draft { background: var(--text-muted); color: white; }
.badge-sent { background: var(--primary-light); color: var(--primary); }
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-overdue { background: var(--danger-light); color: var(--danger); }
.badge-cancelled { background: var(--danger-light); color: var(--danger); }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-form .search-box {
    width: 200px;
}

.filter-select {
    min-width: 120px;
    width: auto;
}

.filter-form .filter-select[name="status"] {
    min-width: 155px;
}

/* Settings tabs */
.settings-tabs {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    gap: 0;
}

.settings-tabs .nav-link {
    padding: 0.75rem 1.25rem;
    color: var(--text-secondary);
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    margin-bottom: -1px;
    text-decoration: none;
}

.settings-tabs .nav-link:hover {
    color: var(--primary);
}

.settings-tabs .nav-link.active {
    color: var(--primary);
    font-weight: 600;
    background: var(--bg-card);
    border-color: var(--border-color);
}

.settings-tab-content {
    margin-top: 0;
}

/* Table footer with per-page and pagination */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.table-footer-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.table-footer-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.per-page-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.per-page-form label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

.per-page-select {
    width: auto;
    min-width: 70px;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.25rem;
}

.pagination a,
.pagination span {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-primary);
    text-decoration: none;
}

.pagination a:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.pagination .active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #f8f7fa 0%, rgba(10, 50, 108, 0.08) 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 2rem;
    border: 1px solid var(--border-color);
}

.login-card-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-card-brand h1 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-primary);
}
.login-logo {
    max-width: 100%;
    max-height: 80px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: inline-block;
    vertical-align: middle;
}

/* Print */
@media print {
    .layout-menu, .layout-navbar, .btn, .no-print { display: none !important; }
    .layout-page { margin: 0 !important; padding: 0 !important; }
    body { background: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Mobile */
@media (max-width: 992px) {
    .layout-navbar { left: 0; }
    .layout-menu {
        transform: translateX(-100%);
    }
    .layout-menu.open {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0,0,0,0.2);
    }
    .layout-page { margin-left: 0; }
}
