/* ===========================
   Deadlock & Recovery - Light Theme
   =========================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-orange: #f59e0b;
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 25px 30px;
    margin-bottom: 25px;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo i {
    font-size: 2rem;
    color: var(--accent-red);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

header p {
    color: var(--gray-500);
    font-size: 0.95rem;
}

.header-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-success {
    background: var(--accent-green);
    color: var(--white);
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--accent-red);
    color: var(--white);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: var(--accent-orange);
    color: var(--white);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-back {
    background: var(--white);
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
}

.btn-back:hover {
    background: var(--gray-50);
    color: var(--gray-800);
}

.btn-tutorial {
    background: var(--accent-blue);
    color: var(--white);
}

.btn-demo {
    background: var(--accent-orange);
    color: var(--white);
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
}

/* Tabs */
.tab-container {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    background: var(--white);
    padding: 8px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}

.tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab:hover {
    background: var(--gray-100);
}

.tab.active {
    background: var(--primary);
    color: var(--white);
}

.tab i {
    font-size: 16px;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Sections */
.section {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 25px;
    margin-bottom: 25px;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.section-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-800);
}

.section-header h2 i {
    color: var(--primary);
}

/* Graph Canvas */
.graph-container {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

.graph-canvas {
    width: 100%;
    height: 400px;
}

/* Graph Controls */
.graph-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Node Palette */
.node-palette {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.palette-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 15px 20px;
    background: var(--white);
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    cursor: grab;
    transition: all 0.2s ease;
}

.palette-item:hover {
    border-color: var(--primary);
    background: #eef2ff;
}

.palette-item i {
    font-size: 24px;
}

.palette-item.process i {
    color: var(--accent-blue);
}

.palette-item.resource i {
    color: var(--accent-green);
}

.palette-item span {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-600);
}

/* Graph Legend */
.graph-legend {
    display: flex;
    gap: 20px;
    margin-top: 15px;
    padding: 10px 15px;
    background: var(--gray-50);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-600);
}

.legend-circle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.legend-circle.process {
    background: linear-gradient(135deg, var(--accent-blue), #1d4ed8);
}

.legend-circle.deadlock {
    background: var(--accent-red);
}

.legend-square {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--accent-green), #059669);
}

.legend-arrow {
    width: 30px;
    height: 4px;
    border-radius: 2px;
    position: relative;
}

.legend-arrow::after {
    content: '';
    position: absolute;
    right: 0;
    top: -4px;
    border: 6px solid transparent;
    border-left-color: inherit;
}

.legend-arrow.request {
    background: #fbbf24;
}

.legend-arrow.request::after {
    border-left-color: #fbbf24;
}

.legend-arrow.allocation {
    background: #a78bfa;
}

.legend-arrow.allocation::after {
    border-left-color: #a78bfa;
}

/* Graph Nodes */
.graph-nodes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.graph-node {
    position: absolute;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: white;
    cursor: grab;
    pointer-events: auto;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    z-index: 10;
}

.graph-node:hover {
    transform: scale(1.1);
    z-index: 20;
}

.graph-node:active {
    cursor: grabbing;
}

.process-node {
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #1d4ed8);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.resource-node {
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent-green), #059669);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.node-deadlock {
    animation: deadlockPulse 0.5s ease infinite alternate;
}

@keyframes deadlockPulse {
    from {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    to {
        box-shadow: 0 0 20px 5px rgba(239, 68, 68, 0.5);
    }
}

/* Graph SVG */
#graphSvg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Edge Controls */
.edge-controls {
    margin-top: 20px;
    padding: 20px;
    background: var(--gray-50);
    border-radius: var(--radius-md);
}

.edge-controls h3 {
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--gray-700);
}

.edge-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.edge-form select {
    padding: 10px 15px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    min-width: 150px;
    background: white;
}

.edge-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Detection Result */
.detection-result {
    padding: 20px;
    border-radius: var(--radius-md);
    margin-top: 15px;
}

.detection-result.deadlock {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border: 2px solid var(--accent-red);
}

.detection-result.safe {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 2px solid var(--accent-green);
}

.detection-result h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.detection-result.deadlock h3 {
    color: var(--accent-red);
}

.detection-result.safe h3 {
    color: var(--accent-green);
}

.cycle-display {
    padding: 15px;
    background: white;
    border-radius: var(--radius);
    font-family: 'Fira Code', monospace;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent-red);
    text-align: center;
    margin-top: 10px;
}

.legend-color {
    width: 20px;
    height: 4px;
    border-radius: 2px;
}

.legend-color.request {
    background: var(--accent-orange);
}

.legend-color.allocation {
    background: var(--accent-green);
}

/* Status Messages */
.status-message {
    padding: 15px 20px;
    border-radius: var(--radius);
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-message.success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: var(--accent-green);
}

.status-message.danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--accent-red);
}

.status-message.warning {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #b45309;
}

.status-message i {
    font-size: 1.25rem;
}

/* Banker's Algorithm */
.bankers-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

/* Matrix Tables */
.matrix-section {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 20px;
}

.matrix-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.matrix-section h3 i {
    color: var(--primary);
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.matrix-table th {
    background: var(--gray-100);
    padding: 10px;
    text-align: center;
    font-weight: 600;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.matrix-table td {
    padding: 8px;
    text-align: center;
    border: 1px solid var(--gray-200);
    background: var(--white);
}

.matrix-table input {
    width: 50px;
    padding: 6px;
    text-align: center;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
}

.matrix-table input:focus {
    outline: none;
    border-color: var(--primary);
}

.matrix-table .row-label {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-600);
}

/* Safe Sequence */
.safe-sequence {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--radius-md);
    padding: 20px;
    margin-top: 20px;
}

.safe-sequence h3 {
    color: var(--accent-green);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sequence-display {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sequence-step {
    padding: 10px 20px;
    background: var(--white);
    border: 2px solid var(--accent-green);
    border-radius: var(--radius);
    font-weight: 600;
    color: var(--accent-green);
}

.sequence-arrow {
    color: var(--gray-400);
    font-size: 1.25rem;
}

/* Unsafe State */
.unsafe-state {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    padding: 20px;
    margin-top: 20px;
}

.unsafe-state h3 {
    color: var(--accent-red);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Recovery Strategies */
.recovery-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.recovery-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 25px;
    transition: all 0.2s ease;
}

.recovery-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.recovery-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--primary), var(--accent-purple));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.recovery-icon i {
    font-size: 1.5rem;
    color: var(--white);
}

.recovery-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 10px;
}

.recovery-card p {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-bottom: 15px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 30px;
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--gray-900);
}

.modal-content h2 i {
    color: var(--primary);
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-400);
}

.close:hover {
    color: var(--gray-600);
}

/* Tutorial */
.tutorial-content {
    max-height: 60vh;
    overflow-y: auto;
}

.tutorial-section {
    margin-bottom: 20px;
}

.tutorial-section h3 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1rem;
}

.tutorial-section p,
.tutorial-section ul {
    color: var(--gray-600);
    font-size: 0.95rem;
    line-height: 1.7;
}

.tutorial-section ul {
    padding-left: 20px;
}

.tutorial-section li {
    margin-bottom: 5px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        padding: 15px;
    }
    
    .bankers-container {
        gap: 20px;
    }
    
    .graph-area {
        min-height: 350px;
    }
}

@media (max-width: 900px) {
    .bankers-container {
        grid-template-columns: 1fr;
    }
    
    .tab-container {
        flex-wrap: wrap;
    }
    
    .tab {
        flex: 1;
        justify-content: center;
    }
    
    .recovery-container {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    header {
        padding: 20px;
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }
    
    .logo h1 {
        font-size: 1.3rem;
    }
    
    .header-buttons {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .matrix-section {
        padding: 15px;
    }
    
    .matrix-table input {
        width: 40px;
        padding: 5px;
    }
    
    .legend-item {
        flex-direction: column;
        gap: 5px;
        font-size: 12px;
    }
    
    .recovery-container {
        grid-template-columns: 1fr;
    }
    
    .edge-form {
        flex-direction: column;
    }
    
    .edge-form select {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }
    
    header {
        padding: 15px;
    }
    
    .header-buttons .btn span {
        display: none;
    }
    
    .tab {
        padding: 10px 15px;
        font-size: 13px;
    }
    
    .tab span {
        display: none;
    }
    
    .graph-area {
        min-height: 280px;
    }
    
    .graph-node {
        width: 45px;
        height: 45px;
        font-size: 12px;
    }
    
    .section {
        padding: 15px;
    }
    
    .section h3 {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 1.1rem;
    }
    
    .header-buttons {
        gap: 8px;
        flex-wrap: wrap;
        width: 100%;
        justify-content: center;
    }
    
    .header-buttons .btn {
        flex: 1;
        min-width: 45%;
        text-align: center;
        justify-content: center;
    }
    
    .tab-container {
        gap: 5px;
        flex-wrap: wrap;
    }
    
    .tab {
        padding: 8px 12px;
        font-size: 12px;
        flex: 1;
        min-width: 45%;
        text-align: center;
        justify-content: center;
    }
    
    .matrix-table th,
    .matrix-table td {
        padding: 6px;
        font-size: 12px;
    }
    
    .matrix-table input {
        width: 35px;
        padding: 4px;
        font-size: 12px;
    }
    
    .recovery-card {
        padding: 15px;
    }
    
    .recovery-icon {
        width: 40px;
        height: 40px;
    }
    
    .modal-content {
        padding: 20px;
        margin: 10px;
    }
    
    .graph-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .graph-controls .btn {
        width: 100%;
    }
    
    .edge-form {
        flex-direction: column;
        gap: 10px;
    }
    
    .edge-form select,
    .edge-form .btn {
        width: 100%;
    }
}

@media (max-width: 360px) {
    header {
        padding: 12px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .container {
        padding: 8px;
    }
    
    .graph-node {
        width: 40px;
        height: 40px;
        font-size: 11px;
    }
    
    .section {
        padding: 12px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
    }
    
    .tab {
        min-height: 44px;
    }
    
    .graph-node {
        min-width: 50px;
        min-height: 50px;
    }
    
    .matrix-table input {
        min-height: 36px;
    }
    
    .edge-form select {
        min-height: 44px;
    }
    
    .recovery-card {
        padding: 20px;
    }
}

/* Landscape mode on small devices */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 10px 20px;
    }
    
    .header-content {
        flex-direction: row;
    }
    
    .graph-area {
        min-height: 200px;
    }
    
    .modal-content {
        max-height: 95vh;
        padding: 15px;
    }
}
